jQuery onload - .load() - event not working with a dynamically loaded iframe

后端 未结 4 1719
忘了有多久
忘了有多久 2021-01-02 00:15

My script loads an iframe when the user clicks a button. I want to call another function after the iframe loads, but it\'s not working. The iframe does load normally, but

4条回答
  •  时光说笑
    2021-01-02 00:35

    If the document you are loading in the iframe is something you control, try putting the load handler into that document. If you need the parent document to do something after the iframe loads you can call a function in the parent from the child:

    // in parent doc
    function myIframeLoaded() {
       // do something
    }
    
    // in iframe doc
    $(document).load(function() {   // or .ready()
       parent.myIframeLoaded();
    }
    

提交回复
热议问题