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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -