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

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

问题描述

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

此代码适用于IE,Firefox和Safari。但不要在Chrome和Opera中运行。这些浏览器打印整个页面。



我试图使用这个主题。但它并没有帮助我。



有人可以帮助我吗?

解决方案

这是Opera中的一个已知错误。除了以上解决方法的想法之外,您可能还想玩这样的东西:

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

我没有测试过,但它应该在弹出窗口中创建页面的副本并将其打印出来,而无需再次从服务器加载内容或丢失可能需要打印的任何DOM修改。


I'm trying to print iframe content.

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

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

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

Could someone help me?

解决方案

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();

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天全站免登陆