开发者

How do I abort print?

Is there a way to abort the print event after a user has pressed the web browsers print button?

This works for print buttons within the HTML (jQuery):

print_btn.click(function() {
    if (confirm("Are you sure you want to print? Consider the environment")) {
        window.print();
    }
});

Is ther开发者_运维百科e a way to do the same with the web browsers print button? For IE there seemes to be a onbeforeprint event, but from there I can't find a way to abort the printing.

Thanks!


This isn't possible in general, and honestly I'm quite glad that's the case.

You could, however, do something dirty like make a style sheet that uses media selectors to make everything display: none; when printing, or something similar. I haven't ever tried this but it seems totally within spec (if completely pretentious).


Have you tried to return false; in IE's onbeforeprint event?

I doubt it's possible in any other browsers but IE. Having said that, it wouldn't surprise me if it worked in IE using the onbeforeprint event. Shocking, I know.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜