在 Opera 和 Chrome 中打印 iframe 内容 [英] Print iframe content in Opera and Chrome

查看:21
本文介绍了在 Opera 和 Chrome 中打印 iframe 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印 iframe 内容.

I'm trying to print iframe content.

contentWindow.focus();
contentWindow.print();

此代码适用于 IE、Firefox 和 Safari.但不适用于 Chrome 和 Opera.这些浏览器会打印整个页面.

This code works in IE, Firefox and Safari. But don't work in Chrome and Opera. These browsers print entire page.

我尝试使用这个主题 如何我是否在 Safari/Chrome 中从 javascript 打印 IFrame.但这对我没有帮助.

I tried to use this topic How do I print an IFrame from javascript in Safari/Chrome. But it didn't help me.

有人可以帮我吗?

推荐答案

这是 Opera 中的一个已知错误.除了上述解决方法的想法外,您可能还想尝试以下方法:

This is a known bug in Opera. In addition to the above ideas for workarounds, you may want to play with something like this:

    var clone=document.documentElement.cloneNode(true)
    var win=window.open('about:blank');
    win.document.replaceChild(clone, win.document.documentElement);
    win.print();

我没有测试过这个,但它应该在弹出窗口中创建页面的副本并打印它,而不必从服务器第二次加载内容或丢失您可能想要打印的任何 DOM 修改.

I have not tested this but it should create a copy of the page in a popup window and print it, without having to load the content a second time from the server or loosing any DOM modifications you may want printed.

这篇关于在 Opera 和 Chrome 中打印 iframe 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆