亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Javascript僅打印iframe內容

Javascript僅打印iframe內容

月關寶盒 2019-08-12 17:26:45
Javascript僅打印iframe內容這是我的代碼<script>var body = "dddddd"    var script = "<script>window.print();</scr'+'ipt>";var newWin = $("#printf")[0].contentWindow.document; newWin.open();newWin.close();$("body",newWin).append(body+script);</script><iframe id="printf"></iframe>這可以,但它打印父頁面,我如何讓它只打印iframe?
查看完整描述

3 回答

?
有只小跳蛙

TA貢獻1824條經驗 獲得超8個贊

我不希望這樣做

試著改為

window.frames["printf"].focus();window.frames["printf"].print();

并使用

<iframe id="printf" name="printf"></iframe>

或者嘗試好老

var newWin = window.frames["printf"];newWin.document.write('<body onload="window.print()">dddd</body>');newWin.document.close();

如果jQuery不能破解它

現場演示


查看完整回答
反對 回復 2019-08-12
?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

document.getElementById("printf").contentWindow.print();

同源政策適用。


查看完整回答
反對 回復 2019-08-12
?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

簡單的方法(在ie7 +,firefox,Chrome,safari上測試)就是這樣

//id is the  id of the iframefunction printFrame(id) {
            var frm = document.getElementById(id).contentWindow;
            frm.focus();// focus on contentWindow is needed on some ie versions
            frm.print();
            return false;}


查看完整回答
反對 回復 2019-08-12
  • 3 回答
  • 0 關注
  • 1130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號