javascript - window.print() refreshes page in iframe when I click cancel -
i have iframe inside website following jquery code in it:
$(document).ready(function() { $('#print_button').click(function() { window.print(); }); });
the problem: when click print button, print dialog opens correctly. printing works correctly well. when click cancel button in print dialog closes refreshes content in iframe.
how can avoid behaviour?
as stated in above comments, form being submitted when button #print_button
clicked. force page refresh.
to prevent this, add return value of false
onclick
event. cancel form submission.
window.print(); return false;
Comments
Post a Comment