开发者

Slowing Down mywindow.print()

开发者 https://www.devze.com 2022-12-30 03:23 出处:网络
I\'m using this nice printing script: <script type=\"text/javascript\"> function PrintElem(elem)

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:

  1. 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).
  2. 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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号