【问题标题】:onload bug in Google Chrome/SafariGoogle Chrome/Safari 中的加载错误
【发布时间】:2014-03-28 19:55:41
【问题描述】:

我有各种打开的链接bootstrapmodals。一些模态框以简单的html 内容打开,其他模态框包含iframe

我正在使用ng-switch 来确定要加载到模式中的内容类型。此问题仅发生在 Google Chrome 和 Safari(即 webkit 浏览器)中。

我在 iframe 中使用 onload 在 iframe 实例化后调用函数。

<div class="modal-body" ng-switch="modal.type">
   <div ng-switch-when="iframe">
      <iframe ng-src="http://plunker.co/group" onload="callMeMaybe();"></iframe>
   </div>
   <div ng-switch-when="html">
      <h1>I'm just plain ol' html up in here.</h1>
   </div>
</div>

问题: Chrome 和 Safari 调用了两次 onload 函数。而 Firefox 和 IE 正确调用该函数一次。

在 Chrome/Safari 中我可以做些什么来防止这种行为?

这是plunkr

【问题讨论】:

    标签: javascript angularjs twitter-bootstrap iframe webkit


    【解决方案1】:

    显然,在 webkit 浏览器上,iframe 上的 onload 事件会触发两次。一次是在创建 iframe 时,然后是在设置 src 时。

    根据这个答案:https://stackoverflow.com/a/15880489/3170216

    如果您在 iframe 元素附加到正文之后附加 onload 事件,则可以防止这种行为。但我不确定如何在你的情况下做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 2013-09-19
      • 2014-09-23
      • 2011-06-17
      • 2018-08-24
      • 1970-01-01
      相关资源
      最近更新 更多