window.print不能在Firefox中使用 [英] window.print not working in Firefox

查看:144
本文介绍了window.print不能在Firefox中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CallPrint(){
var prtContent = document.getElementById('<%= pnlDelete.ClientID%>');

  
var winPrint = window.open('','','left = 0,top = 0,width = 800,height = 600,toolbar = 0,scrollbars = 0,status = 0);
winPrint.document.write(< h3>摘要< / h3>< br />+ prtContent.innerHTML);
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close();



$ b $ p
$ b

我需要打印div的内容。我正在使用上面的代码来这样做。它在IE中正常工作,但在Firefox中什么都不做。我在这里丢失了一些需要在Firefox中完成的事情吗?

解决方案

这个页面在窗口中,并通过window.opener对象从打开的窗口访问pnlSummary的内容 -


$ b

  function CallPrint() {
var winPrint = window.open('Print.aspx','','left = 0,top = 0,width = 800,height = 600,toolbar = 0,scrollbars = 0,status = 0 );

在Print.aspx页面上,我使用了这个函数 - $ / b>

  function Print(){
var prtContent =< h3>汇总< / h3> + window.opener.document.getElementById('ctl00_cphContent_pnlSummary')。innerHTML;
document.getElementById(printDiv)。innerHTML = prtContent;
window.print();
window.opener.focus();
window.close(); }

并在body onload上调用它。

 < body onload =Print();> 
< form id =form1runat =server>
< div id =printDiv>
< / div>
< / form>
< / body>

这个在IE和Firefox都可以正常工作。


function CallPrint() {
        var prtContent = document.getElementById('<%= pnlDelete.ClientID %>');
        var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
        winPrint.document.write("<h3>Summary</h3><br />" + prtContent.innerHTML);
        winPrint.document.close();
        winPrint.focus();
        winPrint.print();
        winPrint.close();
    }

I have a need where I have to print contents of a div. I am using above code to do so. It is working fine in IE but does nothing in Firefox. Am I missing something here that needs to be done in Firefox?

解决方案

Instead of opening a new window without any URL, I opened this page in the window and accessed the contents of the pnlSummary from the opened window via window.opener object –

function CallPrint() {
    var winPrint = window.open('Print.aspx', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
}

On Print.aspx page I used this function –

function Print() {
    var prtContent = "<h3>Summary</h3>" + window.opener.document.getElementById('ctl00_cphContent_pnlSummary').innerHTML;
    document.getElementById("printDiv").innerHTML = prtContent;
    window.print();
    window.opener.focus();
    window.close(); }

and called it on body onload.

<body onload="Print();">
    <form id="form1" runat="server">
    <div id="printDiv">
    </div>
    </form>
</body>

This is working fine in both IE and Firefox.

这篇关于window.print不能在Firefox中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆