如何在 IE7 中删除 iframe 边框? [复制]

Posted

技术标签:

【中文标题】如何在 IE7 中删除 iframe 边框? [复制]【英文标题】:How to remove iframe border in IE7? [duplicate] 【发布时间】:2011-05-26 05:27:47 【问题描述】:

在除 IE7 之外的任何浏览器中移除 iframe 的边框都没有问题... 我的问题是:如何在使用 IE7 打开页面时删除/隐藏 iframe 边框?

【问题讨论】:

【参考方案1】:

frameborder='0' border='0' style="border:0;" 不这样做?

【讨论】:

我必须将 frameborder 中的 B 大写才能使其正常工作,因此您将拥有:frameBorder="0" 从来不用大写。你确定需要吗?【参考方案2】:

试试这个。它会在 IE 和其他浏览器中找到任何 iframe 元素并删除它们的边框(尽管您可以在非 IE 浏览器中设置“border : none;”样式而不是使用 javascript)。并且即使在 iframe 生成并在文档中就位之后使用它也可以工作(例如,以纯 html 而不是 JavaScript 添加的 iframe)!

这似乎可行,因为 IE 创建边框,而不是像您期望的那样在 iframe 元素上,而是在 iframe 的 CONTENT 上——在 iframe 在 BOM 中创建之后。 ($@&*#@!!! IE!!!)

注意:只有当父窗口和 iframe 来自相同的来源(相同的域、端口、协议等)时,IE 部分才有效(当然)。否则脚本将在 IE 错误控制台中出现“拒绝访问”错误。如果发生这种情况,您唯一的选择是在生成之前设置它,正如其他人所指出的那样,或者使用非标准 frameBorder="0" 属性。 (或者只是让 IE 看​​起来很丑——我目前最喜欢的选项;))

我花了好几个小时工作到绝望的地步才弄清楚这一点......

享受。 :)

// =========================================================================
// Remove borders on iFrames

if (window.document.getElementsByTagName("iframe"))
   
      var iFrameElements = window.document.getElementsByTagName("iframe");
      for (var i = 0; i < iFrameElements.length; i++)
         
            iFrameElements[i].frameBorder="0";   //  For other browsers.
            iFrameElements[i].setAttribute("frameBorder", "0");   //  For other browsers (just a backup for the above).
            iFrameElements[i].contentWindow.document.body.style.border="none";   //  For IE.
         
   

【讨论】:

以上是关于如何在 IE7 中删除 iframe 边框? [复制]的主要内容,如果未能解决你的问题,请参考以下文章

删除IE7 activex边框

如何在ie6/ie7/ie8中实现iframe背景透明

如何在 IE8 中去除 iframe 的边框

如何在 iframe 周围创建边框?

为啥 iframe 的 CSS 边框会闪烁以及如何修复它?

Fancybox 2,带表单的 iframe,在 IE7 中不起作用