开发者

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

开发者 https://www.devze.com 2023-01-25 22:02 出处:网络
I have a an iframe inside my website with the following jquery code in it: $(document).ready(function() {

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

精彩评论

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