Detect failure to load contents of an iframe

前端 未结 6 1782
迷失自我
迷失自我 2020-12-01 06:59

I can detect when the content of an iframe has loaded using the load event. Unfortunately, for my purposes, there are two problems with this:

  • If there
6条回答
  •  清歌不尽
    2020-12-01 07:46

    If you have control over the iframe page (and the pages are on the same domain name), a strategy could be as follows:

    • In the parent document, initialize a variable var iFrameLoaded = false;
    • When the iframe document is loaded, set this variable in the parent to true calling from the iframe document a parent's function (setIFrameLoaded(); for example).
    • check the iFrameLoaded flag using the timer object (set the timer to your preferred timeout limit) - if the flag is still false you can tell that the iframe was not regularly loaded.

    I hope this helps.

提交回复
热议问题