Slowing Down mywindow.print()
I'm using this nice printing script:
<script type="text/javascript">
function PrintElem(elem)
{
开发者_运维技巧 Popup($(elem).text());
}
function Popup(data)
{
var mywindow = window.open('', 'my div', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.print();
return true;
}
</script>
</head>
<body>
It works fine except for two things:
mywindow.print()
is triggered before the page has completely loaded so you can't see the material in the window to be printed (if you select "Print" it prints correctly though).- The print dialog box opens on top of the window blocking the contents (presuming #1 is an easy fix). How can it positioned?
Thanks - TY
try
mywindow.document.body.onload = function(){
mywindow.print();
};
or
setTimeout(function(){
mywindow.print();
}, 100);
hope this helps!
精彩评论