开发者

window.print() refreshes page in iframe when I click cancel

I have a an iframe inside my website with the following jquery code in it:

$(document).ready(function() {

    $('#print_button').click(function() {
     开发者_如何学运维   window.print();
    });

});

The problem: When I click the print button, the print dialog opens correctly. Printing works correctly as well. But when I click the cancel button in the print dialog it closes but it also refreshes content in the iframe.

How can I avoid this behaviour?


As stated in the above comments, a form is being submitted when the button #print_button is clicked. This would force the page to refresh.

To prevent this, add a return value of false to the onclick event. This would cancel the form submission.

window.print();
return false;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜