为什么IE8不能设置window.onload?

发布于 2024-09-08 18:52:23 字数 202 浏览 8 评论 0原文

我有以下功能,在 Firefox 中工作正常,但在 IE8 中不起作用

function print(url) {
    var w = window.open(url);
    w.onload = function() {
        w.print();
    };
}

我想打开一个网页并立即打开打印对话框。

I have the following function, which works fine in Firefox, but will do nothing in IE8

function print(url) {
    var w = window.open(url);
    w.onload = function() {
        w.print();
    };
}

I want to open a webpage and immediately open the print dialogue.

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

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

发布评论

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

评论(2

岁月染过的梦 2024-09-15 18:52:23

如果您的手位于 url 页面上,请在那里拨打电话。
在 HTML 中,位于 BODY 标记的末尾。
在您的通话中添加 SCRIPT 标签

<body>
  ...
  <script>
    window.print();
  </script>
</body>

If you have the hand on the page at url, place the call there.
In the HTML, at the end of the BODY tag.
Add a SCRIPT tag with your call

<body>
  ...
  <script>
    window.print();
  </script>
</body>
热鲨 2024-09-15 18:52:23

一般来说,您无法处理当前窗口之外的窗口对象的 load 事件,因为它不适用于所有浏览器。您需要使用加载到新窗口中的文档中的脚本来处理 load 事件。您的处理程序可以调用 window.print() 本身,或者,如果您需要将功能保留在原始窗口中,它可以使用 window.opener 调用原始窗口 属性或设置一个标志,使原始窗口中的脚本可以轮询。

In general, you can't handle the load event of window objects outside the current window because it doesn't work in all browsers. You need to handle the load event using a script in the document loaded into the new window. Your handler could either call window.print() itself, or, if you need to keep the functionality within the original window, it could make a call to the original window using the window.opener property or set a flag that script in the original window can poll.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文