为什么IE8不能设置window.onload?
我有以下功能,在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的手位于
url
页面上,请在那里拨打电话。在 HTML 中,位于 BODY 标记的末尾。
在您的通话中添加 SCRIPT 标签
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
一般来说,您无法处理当前窗口之外的窗口对象的
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 theload
event using a script in the document loaded into the new window. Your handler could either callwindow.print()
itself, or, if you need to keep the functionality within the original window, it could make a call to the original window using thewindow.opener
property or set a flag that script in the original window can poll.