WPF Web 浏览器内容大小

发布于 2024-11-07 19:45:53 字数 67 浏览 0 评论 0原文

我查看了所有相关问题,但无法得到答案。

如何获取 WPF 中 WebBrowser 控件的当前内容大小?

I reviewed all of the related questions but was unable to get an answer.

How do I get the current content size of the WebBrowser control in WPF?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜清冷一曲。 2024-11-14 19:45:53

要确定浏览器窗口的实际大小(使用 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

注意:

  1. 如果上述代码在框架或 iframe 内执行,它将为您提供框架的宽度和高度。
  2. 计算的宽度和高度不包括标题栏、菜单栏、状态栏或工具栏,但可能包括水平和垂直滚动条(如果有)。
  3. 使用 document.body.offsetWidth 和 offsetHeight 的代码应在浏览器解析标签后执行。
  4. 如果用户调整浏览器窗口的大小,您可能需要重新计算宽度和高度(使用 window.onresize 来执行此操作)。
  5. 同样,如果用户放大(或缩小),您可能还需要重新计算宽度和高度。

To determine the actual size(using javascript) of the browser window, use the following properties:

in Internet Explorer (backward-compatibility mode):

document.body.offsetWidth, document.body.offsetHeight

in Internet Explorer (standards mode, document.compatMode=='CSS1Compat'):

document.documentElement.offsetWidth, document.documentElement.offsetHeight

in most other browsers:

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);

In your browser, this code produces the following output:

Window width = 1280
Window height = 675

Notes:

  1. If the above code executes within a frame or iframe, it will give you the frame's width and height.
  2. The computed width and height do not include the title bar, menu bar, status bar, or toolbar(s) - but may include the horizontal and vertical scrollbar(s), if any.
  3. The code that uses document.body.offsetWidth and offsetHeight should be executed after the browser has parsed the tag.
  4. If the user resizes the browser window, you may need to recompute the width and height (use window.onresize to do so).
  5. Similarly, if the user zooms in (or zooms out) you may also need to recompute the width and height.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文