Iframe内容加载和onload事件

问题描述 投票:0回答:1

有以下代码

<iframe id="myframe" src="..."></iframe>

<script>
document.getElementById('myframe').onload = function() {
  alert('myframe is loaded');
};
</script>

我说的对吗?

iframe
内容是由额外的线程加载的,因此可能存在竞争条件?是否有可能在脚本中的事件处理程序(在主线程中运行)之前加载
iframe
内容,导致
alert
更新显示?

javascript html iframe onload
1个回答
-1
投票

  

  function iframeDidLoad(){
       alert("Hello World");
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe id="myiframe" src="#" onLoad="iframeDidLoad();"></iframe>

© www.soinside.com 2019 - 2024. All rights reserved.