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
< a href =http://plungjan.name/SO/testprintiframe.html> 现场演示
这篇关于Javascript仅打印iframe内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文