【问题标题】:how can i do to hide iframe in ie 6,7,8? setting attribute of style = "display:none" does not work!如何在 ie 6、7、8 中隐藏 iframe? style = "display:none" 的设置属性不起作用!
【发布时间】:2011-03-24 15:12:41
【问题描述】:

如何在 ie 6,7,8 中隐藏 iframe? style = "display:none" 的设置属性不起作用!

抱歉,我忘记发布上下文了。

iframe是由javascript动态生成的。如:

  function addIframe(node) {  
      var iframe = document.createElement("div");  
      iframe.src = ****;  
      iframe.style = "display:none";   
      node.appendChild(iframe);   
} 

上述函数生成的隐藏帧在firefox和chrome中有效,在ie中失败。

【问题讨论】:

  • 对我来说 style="display: none;" 有效,但它提供了一个 javascript 异常 access is denied
  • 使用iframe.style.cssText = 'display:none;,或者更好的是iframe.style.display = 'none';

标签: iframe cross-browser hide


【解决方案1】:

您可以尝试将其移出屏幕。小心这样的事情,因为尝试隐藏 iframe 可能会带来安全隐患。

.some-selector {
  margin-left: -2000px;
  position: absolute;
}

【讨论】:

    【解决方案2】:

    仅针对 IE8

    iframe { //display:none }
    

    针对IE7、IE6

    iframe { *display:none }
    

    【讨论】:

      【解决方案3】:

      它应该工作。试试display:none !important。否则,尝试丑陋的黑客攻击

      border:none;
      width:1px;
      height:1px;
      visibility:hidden
      

      【讨论】:

      • 其他技巧是给它一个绝对位置,比如 top:-5000px
      猜你喜欢
      • 1970-01-01
      • 2012-04-25
      • 2016-09-29
      • 2012-04-20
      • 1970-01-01
      • 2014-02-15
      • 2020-05-11
      • 1970-01-01
      • 2022-01-10
      相关资源
      最近更新 更多