Javascript 仅打印 iframe 内容 [英] Javascript Print iframe contents only
本文介绍了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?
This works but it prints the parent page, how do I get it to print just the iframe?
推荐答案
我认为这不会奏效
试试
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 无法破解它
if jQuery cannot hack it
这篇关于Javascript 仅打印 iframe 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文