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

查看:19
本文介绍了在 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.

这是点击打印链接时调用的函数:

This is the function that gets called when the print link is clicked:

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 打印样式,但我打印的内容与页面上的内容不同,因此需要将 html 加载到隐藏的 iframe 中.

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 的可见性:隐藏;导致浏览器打印父级.将样式更改为 height:0px;宽度: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天全站免登陆