Created
November 20, 2019 19:39
-
-
Save Goddard/dc043b8cf8f45987d96bdb9ad5aeaf09 to your computer and use it in GitHub Desktop.
Chrome print is blocking even though it is not in the same window or tab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function sleep(milliseconds) { | |
var start = new Date().getTime(); | |
for (var i = 0; i < 1e7; i++) { | |
if ((new Date().getTime() - start) > milliseconds){ | |
break; | |
} | |
} | |
} | |
var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0'); | |
winPrint.document.write('<title>Print Report</title><br /><br /> Hello World'); | |
winPrint.document.close(); | |
winPrint.focus(); | |
winPrint.print(); | |
winPrint.close(); | |
//you wont see this executed because the javascript print is blocking | |
while (true) { | |
console.log('still running js in background'); | |
sleep(5000); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment