2013-07-17 203 views
1

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

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

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

我需要打印的内容。

+0

你见过这个[的Javascript只打印iframe内容](http://stackoverflow.com/questions/9616426/javascrip叔打印iframe的内容只)?? –

+0

是的,我见过。无法使用ifram。如果在一个不工作的多个iframe中使用 – user2354274

回答

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');" /> 
+0

我试过它不工作。我正在使用新的chtml页面打印MVC 4 – user2354274

+0

? –

+0

号只是要传给iframe内容的打印机 – user2354274