Dynamically create an iframe and attach onload event to it

后端 未结 4 2135
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 05:20

I have created a iframe dynamically and added a src attribute to it. Then I have appended this iframe to body of the page. Know I want to attach an onload

4条回答
  •  甜味超标
    2021-02-08 06:01

    I doubt you can attach an onload event to an iframe. It will not work on all browsers. You can on the other hand check if the iframe was loaded by:

    window.onload=function()
    {
    var iframe=document.getElementById('myframe');
    if(iframe) 
        alert('The iframe has just been loaded.');
    }
    

    Or use AJAX to load the content in your container. With AJAX you can set a proper load-complete event.

提交回复
热议问题