【问题标题】:How to Print iframe content [duplicate]如何打印 iframe 内容 [重复]
【发布时间】:2013-07-17 10:26:38
【问题描述】:

如何打印 iframe 内部内容。在这个 iframe URL 页面中还有一个 iframe。

我已将此 URL 用于我的 iframe。

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

我想打印这个内容。

【问题讨论】:

标签: asp.net c#-4.0


【解决方案1】:

试试这个,

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

【讨论】:

  • 我试过它不起作用。我正在使用 MVC 4
  • 你用新的chtml页面打印?
  • 没有。只想将 iframe 内容传递给打印机
猜你喜欢
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2012-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多