Reputation: 123
I have a page that displays a list of "tickets". On each of these tickets, I'd like a "print" button which prints off just that ticket. I have this all working (cutting out the relevant info ready for printing, changing the colours to black on white etc) except that I would like it to automatically print the document rather than the user having to hit print (or Ctrl+P). When I call window.print() in javascript, it just hangs the browser (I've tried Chrome, Firefox and IE). If I manually press Ctrl+P or the print button, it works fine.
Has anyone ever come across this before, it seems pretty odd?
Upvotes: 2
Views: 4394
Reputation: 2773
If you are using jQuery, you could try the following to print if document is loaded
$(document).ready(function(){
window.print();
});
Or as Pursse suggested
$(document).ready(function(){
setTimeout(function(){
window.print();
}, 1000);
});
Upvotes: 2