问题描述
我创建了一个订单表单,用户javascript在客户点击打印页面时创建一个新的html
文档。按钮。
创建新文档后,然后打印文档并使用以下代码关闭它:
< body onload =" window.print(); window.close();">
这个工作正常(或者至少我期望它在MS下工作的方式
Internet Explorer,但是它会让Netscape陷入崩溃状态
有没有人能解释为什么?
提前谢谢你,
Stephen
I have created an order form that users javascript to create a new html
document when the customers clicks the "print page" button.
Once the new document has been created it then prints the document and
closes it with the following code:
<body onload="window.print(); window.close();">
This works correctly (or at least the way I expect it to work under MS
Internet Explorer, but it cuases Netscape to "crash"
Does anyone have an explanation as to why?
Thank you in advance,
Stephen
推荐答案
你试图关闭显示你想要的文件的窗口
打印。
PointedEars
You are trying to close the window that displays the document you want to
print.
PointedEars
我在Firefox 1.5中的测试似乎表明window.print是异步的
;也就是说,脚本不会等待对话框在继续之前关闭
的框。例如,如果你将onload
处理程序更改为以下内容:
< body onload =" window.print(); alert(''foo'');">
....然后Firefox将显示foo警报首先,然后是打印
对话框。
不幸的是,似乎window.print从未成为任何一部分
正式规范,因此询问同步或异步是否是正确行为是没有意义的。但是,它是非常明显的不管怎样,它不应该'能够使
浏览器崩溃。
- David
My testing in Firefox 1.5 seems to indicate that window.print is
asynchronous; that is, the script does not wait for the dialog box to
be closed before continuing. For example, if you change your onload
handler to the following:
<body onload="window.print(); alert(''foo'');">
....then Firefox will show the "foo" alert first, and then the Print
dialog.
Unfortunately, it seems that window.print has never been part of any
formal specification, so it''s meaningless to ask whether being
synchronous or asynchronous is the "correct" behavior. However, it''s
pretty obvious that no matter what, it shouldn''t be able to crash the
browser.
-- David
这篇关于< body onload =" window.print(); window.close()的;">的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!