【问题标题】:hidden iframe issue with iphone safariiphone safari 隐藏的 iframe 问题
【发布时间】:2011-06-06 21:21:50
【问题描述】:

Safari iphone/ipad 不支持 iframe 上的宽度和高度为 0px,而是放一个大的。

除了将 display 设置为 none 之外,有没有人看到或找到解决方法,因为 0px 似乎适用于所有浏览器。

【问题讨论】:

    标签: javascript html


    【解决方案1】:

    我通过清零我能找到的每个参数来解决这个问题:

    var el = document.createElement("iframe");
    el.setAttribute('id', 'yourFrameId');
    el.height = 0;el.width = 0;
    el.hspace="0";el.vspace="0";
    el.marginheight="0";el.marginwidth="0";
    el.frameBorder = "0";el.scrolling = "No";
    

    或内联:

    <iframe src="test.html" id="yourFrameId" width="0" marginwidth="0" height="0" marginheight="0" align="top" scrolling="No" frameborder="0" hspace="0" vspace="0">Browser not compatible. </iframe>
    

    我还在 CSS 中设置了 display: none。

    这让它在 iOS 上为我工作。尚未在其他移动浏览器上测试过,但如果您遇到问题,您可以尝试设置 position: absolute, top: -9999px 等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2012-09-12
      • 2011-02-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      相关资源
      最近更新 更多