【问题标题】:update height of iframe on chrome (android)在 chrome (android) 上更新 iframe 的高度
【发布时间】:2023-04-01 16:04:01
【问题描述】:

我们有动态加载 iFrame 以显示外部内容的 javascript 小部件。当 iframe 已加载或内容已调整大小时,它会通过 postMessage 发送消息。 Widget 获取消息并调整 iframe 大小:

iframe.style.height = msg.value + 'px';

它在大多数浏览器上都能正常工作,除了 Android 5.0 上的 chrome 50。此外,此代码不适用于 browserstack 上的 Windows Mobile Emulator。我试图改变属性和属性:

iframe.setAttribute("height", msg.value + 'px');
iframe.height = msg.value;
iframe.style.height = msg.value + 'px';

但它不起作用。

高度改变后,我检查了它:

setTimeout(function() {
    alert(iframe.style.height)
},
10000);

警报显示 iframe 的高度已更改,但 iframe 未在页面上调整大小。

我不明白如何解决它。有没有人遇到同样的问题?

【问题讨论】:

    标签: javascript android google-chrome iframe


    【解决方案1】:

    这是 css 样式。我已经设置了!important 属性:

    iframe.setAttribute('style', 'width: ' +  msg.value + 'px !important');
    

    然后它就起作用了。

    【讨论】:

      猜你喜欢
      • 2011-10-11
      • 2011-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 2015-08-20
      • 2016-11-29
      • 1970-01-01
      相关资源
      最近更新 更多