在IE中打印隐藏的iFrame [英] Printing a hidden iFrame in IE

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

问题描述

此解决方案在Firefox 3.0+中正常工作,但IE8 / 7只是打印整个页面,而不是特定的iframe。

This solution works fine in Firefox 3.0+, but IE8/7 is just printing the entire page, not the specific iframe.

当打印链接被点击时:

var printfunc= function(){
  var url = http://someurl.aspx;
  //This iFrame has style="visibility: hidden; position: absolute; left: -9000px;"
  var printIFrame = GetObj('PrintIFrame');
  printIFrame.src = url;
}

被加载到隐藏的iframe中的aspx调用onload上的打印函数事件处理程序:

The aspx that gets loaded into the hidden iframe calls the print function on the onload event handler:

<body onload="PrintJS.Print();">

打印功能:

 this.Print = function(){
      self.focus();
      self.print();
      return false;
 }

我也尝试过window而不是self。这两个解决方案在FF工作正常,但IE似乎没有得到范围的权利。有什么想法吗?跨浏览器解决方案将是伟大的!此外,我宁愿使用CSS打印样式,但我打印的内容不同于页面上的,因此需要加载到隐藏的iframe的html。

I've also tried this with "window" instead of "self". Both solutions work fine in FF but IE doesn't seem to get the scoping right. Any thoughts? A cross-browser solution would be great! Also, I'd rather use CSS print styles, but the content that I'm printing is different than that on the page, hence the need to load html into a hidden iframe.

推荐答案

解决方案:在IE中,iframe with visibility:hidden;导致浏览器打印父级。将样式更改为height:0px; width:0px;修复此问题。

Solution: In IE, an iframe with visibility: hidden; causes the browser to print the parent. Changing the styles to height:0px; width: 0px; fixes this issue.

这篇关于在IE中打印隐藏的iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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