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:
Is there some way I can reliably determine if either of the above errors occurred?
I'm writing a semi-web semi-desktop application based on Mozilla/XULRunner, so solutions that only work in Mozilla are welcome.
To check if iframe is loaded or it has a content with JavaScript, we can set the iframe's onload property to a function that runs when the iframe is loaded. document. querySelector("iframe"). onload = () => { console.
If you want to check if no page loaded inside iframe, and the iframe is not cross-domain you could check for the existence of the body tag inside of the iframe. If it exists, then something loaded. If the iframe is cross-domain, you will be blocked by the same-origin policy.
If you have control over the iframe page (and the pages are on the same domain name), a strategy could be as follows:
var iFrameLoaded = false;
true
calling from the iframe document a parent's function (setIFrameLoaded();
for example).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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With