如何使用 Window.Eval 将窗口的高度和宽度获取到 c# 中

How can I use Window.Eval to get height and width of window into c#?

本文关键字:获取 高度 Window 何使用 Eval 窗口      更新时间:2023-09-26

我需要在Internet Explorer中获取窗口宽度和高度

最初我使用了一个很好的简单语句 var height = HtmlPage.Window.Eval("innerHeight").ToString();

但是我随后发现这在IE 8中不起作用

似乎有很多不同的方法来获取窗口的宽度和高度,我不确定哪个是最好的,但下面提到了一个获取窗口高度

文档 = 文档;var theHeight = Math.max( doc.body.scrollHeight, doc.documentElement.scrollHeight, doc.body.offsetHeight, doc.documentElement.offsetHeight, doc.body.clientHeight, doc.documentElement.clientHeight);

我的问题是我怎样才能把它放到 Window.Eval 以获得高度?

语法需要是什么?

如果有更好,更可靠的方法来获取窗口宽度和高度,请告诉我,但它需要适用于不同的浏览器

保罗

未经

测试。 只是调整你的代码...

HtmlPage.Window.Eval("Math.max( document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight )").ToString();