javascript - Confirmation message after window.print() -
its known there no way determine whether user clicked print or cancel on print window produced window.print().
so im stuck next best thing ask user if did print successfully.
i have this:
$(document).ready(function(){ window.print(); var = confirm('confirm printing successfull , mark job cards released?'); if(a == true) { $.post('printsuccess'); window.location = '/menu'; } });
trouble is, confirmation box pops before print window does, how can ensure print window appears first?
there few ways make sure print dialog
finished before running code block. browser support varies, may need combine of them match need. see below stackoverflow topics.
the following code should work modern browsers.
var printcompletecallback = function () { var conf = confirm('confirm printing successfull , mark job cards released?'); if (conf) { if (a == true) { $.post('printsuccess'); window.location = '/menu'; } } } window.print(); if (window.onafterprint) { //check if browser supports window.onafterprint event handler (firefox , ie) $(window).one("afterprint", printcompletecallback); } else { //use settimeout solution if onafterprint not supported (chrome) settimeout(printcompletecallback, 0); }
Comments
Post a Comment