Problem defering HTML Print
I'm printing a webpage using the javascript
window.print();
whether enclosed in a document.ready or onload event inline the print dialog often pops up before the content is ready.
Ive tried this
$(document).ready(function() {
setTimeout(printPage(),200000);
function printPage()
{
window.print();
}
});
To no avail, can anyone sugge开发者_开发百科st a way to reliably defer printing until the content is ready
You are passing the return value of printPage
to setTimeout
. You have to omit the parenthesis:
setTimeout(printPage,200000);
I hope you know that 200000ms are more than 3 minutes
printPage()
will call the function.
Or if you want to call when everything is loaded, call the function in the load
event handler:
The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images and sub-frames have finished loading.
window.onload = function() {
window.print();
};
// or if you want to use jQuery
$(window).load(function() {
window.print();
});
so you should be use window.onload instead of document.ready and i think you should be use setTimeout("printPage()",200000);
//setTimeout([string],200000);
精彩评论