简体   繁体   English

如何使用Window.Eval将窗口的高度和宽度转换为C#?

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

I need to get the window width and height in Internet Explorer 我需要在Internet Explorer中获取窗口的宽度和高度

Initially I was using a nice simple statement var height = HtmlPage.Window.Eval("innerHeight").ToString(); 最初,我使用的是一个很好的简单语句var height = HtmlPage.Window.Eval(“ innerHeight”)。ToString();

However I then found out that this doesnt work in IE 8 但是我然后发现这在IE 8中不起作用

There appear to be loads of different ways to get the width and height of a window, I am not sure which is the best, but the one below is mentioned here Get the window height 似乎有多种方式获取窗口的宽度和高度,我不确定哪一种是最好的,但是这里提到了以下一种获取窗口高度的方法

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

My question is how can I put this into Window.Eval to get the height? 我的问题是如何将其放入Window.Eval以获取高度?

What does the syntax need to be? 语法需要是什么?

If there is a better, more reliable way of getting window width and height please let me know, but it needs to work for different browsers 如果有更好,更可靠的获取窗口宽度和高度的方法,请告诉我,但这需要适用于不同的浏览器

Paul 保罗

untested. 未经测试。 just adapting your code... 只是修改您的代码...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM