Skip to content

Instantly share code, notes, and snippets.

@Goddard
Created November 20, 2019 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goddard/dc043b8cf8f45987d96bdb9ad5aeaf09 to your computer and use it in GitHub Desktop.
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
<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