javascript 如何打印 iframe 内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25682414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I print iframe content
提问by Muhiddin Jumaniyazov
回答by Hotted24
Here it is :
这里是 :
Your iframe :
你的 iframe :
<iframe id="printf" name="printf"></iframe>
Printing :
印刷 :
window.frames["printf"].focus();
window.frames["printf"].contentWindow.print();
BTW, try to explain your problem in a better way next time (posting code can help) =)
顺便说一句,下次尝试以更好的方式解释您的问题(发布代码可以提供帮助)=)
Ref: Javascript Print iframe contents only
EDIT :
编辑 :
As OP said didn't work, i'm referring the testpage which was linked in Ref:
正如 OP 所说没有用,我指的是参考文献中链接的测试页:
You can also try this function (same ref, different poster) :
你也可以试试这个功能(相同的参考,不同的海报):
//id is the id of the iframe
function printFrame(id) {
var frm = document.getElementById(id).contentWindow;
frm.focus();// focus on contentWindow is needed on some ie versions
frm.print();
return false;
}