开发者

window.onbeforeunload vs window.print in Internet Explorer

One of my pages shows a discount code, and if you try to navigate away I use the window.onbeforeunload to alert the user to write down the code because otherwise it will be lost forever. That page has also a print button, so the user can print the voucher.

The problem is that, in Internet Explorer when the user click on the link <a href="javascript:window.print();"> , the event window.onbeforeunload is raised. This doesn't happen in Chrome.

Is there a way to solve this?

I've seen that if I try this:

<a href="javascript:alert('herp开发者_如何学C');window.print();">

The 'herp' message appears after the warning showed by window.onbeforeunload, so I don't know how to fix this.


Simply use <a onclick="window.print();"> instead of href attribute.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜