如何打印 iframe 内容

Mux*_*zov 1 javascript iframe

我想打印 iframe 内容但我做不到,我找到了 url我是一个新的程序员,所以我没有理解问题和答案,请提前给我一些简单的
感谢

小智 5

这里是 :

你的 iframe :

<iframe id="printf" name="printf"></iframe>
Run Code Online (Sandbox Code Playgroud)

印刷 :

window.frames["printf"].focus();
window.frames["printf"].contentWindow.print();
Run Code Online (Sandbox Code Playgroud)

顺便说一句,下次尝试以更好的方式解释您的问题(发布代码可以提供帮助)=)

参考Javascript 仅打印 iframe 内容

编辑 :

正如OP所说没有用,我指的是参考文献中链接的测试页:

打印 iframe

你也可以试试这个功能(相同的参考,不同的海报):

//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;
}
Run Code Online (Sandbox Code Playgroud)