【发布时间】:2023-01-30 21:07:04
【问题描述】:
好的...所以这曾经有效...但不再有效了。
我有一个从 asp.net 页面弹出的 html5lightbox,然后通过 JS 调用 window.print()。然后在打印后,通过类似于 window.close() 的方法关闭 html5lightbox。然而,突然间,chrome 将无法正常运行并且 onAfterPrint 事件不会触发。为了简化不起作用的部分,我创建了这个 jsfiddle,它会在加载后打印,然后在打印对话框关闭后发出警报。请注意它在 Edge (IE) 中有效,但在 Chrome 中无效。我错过了什么?
https://jsfiddle.net/Lr7kvoh1/
<html>
<head></head><body>
<h1>HTML DOM Events</h1>
<h2>The afterprint Event</h2>
<p>Use the addEventListener() method to attach an "afterprint" event to the window object.</p>
<h3>Print this document!</h3>
<p><b>Tip</b>: The keyboard shortcut Ctrl+P prints a page.</p>
<script>
window.onload = function () {
window.print();
}
window.onafterprint = function () {
alert("This document is now being printed");
}
</script>
</body></html>`
在网上到处找。找不到任何东西。一直工作到大约一周前......
【问题讨论】:
-
顺便说一句,这是在PC上。
-
我在最新的 chrome 109 版本上也面临完全相同的问题。它的工作 108 版本。我正在使用反应
标签: javascript asp.net