如何打印iframe内容

时间:2013-07-17 10:26:39

标签: asp.net c#-4.0

如何打印iframe内容。在此iframe网址页面中还有一个iframe。

我已将此网址用于我的iframe。

<iframe width="700" height="500" src = "https://www.cashpayment.com/Public/PaymentCenterLocator?MerchantID=946">

我想打印此内容。

1 个答案:

答案 0 :(得分:0)

试试这个,

var mywindow = window.open('', 'iFrameTagId', 'height=500,width=500');
        mywindow.document.write('<html><head><title>title</title>');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);//iFrame data
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

或者您直接打开此页面并在页面加载时使用下面的代码

$(document).ready(function () {
    window.print();
    setTimeout('window.close();', 100);
});

更新代码

function iprint(ptarget) {

        var mywindow = window.open('', 'ptarget', 'height=500,width=500');
        mywindow.document.write('<html><head><title>title</title>');
        mywindow.document.write('</head><body >');
        mywindow.document.write($(ptarget).html()); //iFrame data
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();
    } 

<iframe name="theiframe" id="theiframe" width="700" height="500"  src = "http://localhost:54649/WebSite6/Default.aspx"></iframe> 
 <input type="button" class="btninput" value="print iframe" onclick="iprint('#theiframe');" /> 
相关问题