Detecting DOM Ready State Within an iFrame (jQuery)

后端 未结 1 540
别跟我提以往
别跟我提以往 2021-01-24 12:38

I have a script being run in a document that may or may not be nested in an iframe. I have sorted out the issue of detecting the nested, but I can\'t figure out how to detect t

相关标签:
1条回答
  • 2021-01-24 13:17

    You can place a SCRIPT tag at the end of the iframe BODY tag.
    Then add your code there, it will be executed when the iframe body is loaded.

    You can either run a local JS code of the iframe, or call an object in the parent like:

    <body>
      ...
      <script>
        parent.myObj.iframeLoaded(document.body);
      </script>
    </body>
    

    To my experience, the onload event in IE is not reliable.
    i.e: it won't wait to the JS inside the iframe to be loaded before firing.

    0 讨论(0)
提交回复
热议问题