我查看了所有相关问题,但无法得到答案。
如何在WPF中获取WebBrowser控件的当前内容大小?
答案 0 :(得分:4)
要确定浏览器窗口的实际大小(使用javascript),请使用以下属性:
Internet Explorer中的(向后兼容模式):
document.body.offsetWidth, document.body.offsetHeight
Internet Explorer中的(标准模式,document.compatMode =='CSS1Compat'):
document.documentElement.offsetWidth, document.documentElement.offsetHeight
在大多数其他浏览器中:
window.innerWidth, window.innerHeight
The following code sets the variables winW and winH to the actual width and height of the browser window, and outputs the width and height values. If the user has a very old browser, then winW and winH are set to 630 and 460, respectively.
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
document.writeln('Window width = '+winW);
document.writeln('Window height = '+winH);
在您的浏览器中,此代码会生成以下输出:
Window width = 1280
Window height = 675
注意: