在Chrome浏览器中使用onafterprint苹果浏览器 [英] Using onafterprint in Chrome & Safari
问题描述
我知道直到最近 onafterprint
只是IE本地的。最近HTML5已将其添加到其事件列表中。我只在Firefox中成功使用它,但无法在Chrome或Safari中使用它。
它只在Firefox中正常工作时才起作用:
< body onafterprint =printIt()>
该函数的脚本是这样的:
$(document).ready(function(){
$('。printMe')。click(function(){
window.print();
返回false;
});
});
函数printIt()
{
$('#confirmPrint')。show();
};
点击 .printMe
按钮,打开打印窗口。单击打印或取消将在 #confirmPrint
中显示一条消息。我并不担心能否分辨是否点击取消或打印。我只关心它在Chrome和Safari中的运作。任何帮助深表感谢。我也使用jQuery,如果这还不是很明显的话。
经过一些实验,我想我可以放心地说 onafterprint
不值得考虑。
- 即使用户点击
取消
而不是确定
在打印对话框中 - IE8显然会触发它甚至<
相反,在调用
print()
之后直接做任何你想做的事情,即
$(document).ready(function(){
$('。printMe')。click(function(){
window.print();
printIt();
返回false;
});
});
函数printIt()
{
$('#confirmPrint')。show();
};
I am aware that until recently
onafterprint
was only native to IE. Recently HTML5 has added it to its list of events. I have only been successful in using it in Firefox but cannot get it to function in Chrome or Safari.It appears to only function in Firefox when its used in the body:
<body onafterprint="printIt()">
The script for the function is this:
$(document).ready(function() { $('.printMe').click(function() { window.print(); return false; }); }); function printIt() { $('#confirmPrint').show(); };
By clicking the
.printMe
button, it opens the print window. Clicking print or cancel will show a message in#confirmPrint
. I'm not so worried about being able to tell whether they are clicking cancel or print. I am only concerned with it functioning in Chrome and Safari. Any help is much appreciated. I am using jQuery as well, if that is not already obvious.解决方案After some experiments, I think I can safely say that
onafterprint
is not worth considering.- Firefox fires it even if the user clicked
Cancel
instead ofOK
in the print dialog - IE8 apparently fires it even before the print dialog appears
- Chrome doesn't fire it at all
Instead, just do whatever you wanted to do directly after calling
print()
, i.e.$(document).ready(function() { $('.printMe').click(function() { window.print(); printIt(); return false; }); }); function printIt() { $('#confirmPrint').show(); };
这篇关于在Chrome浏览器中使用onafterprint苹果浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Firefox fires it even if the user clicked