I have an iframe that loads an external domain, and sometimes the domain goes down or expires. I tried to figure out how to determine if the iframe page is loaded or not. I cannot use AJAX because the domain is different from the main page (protection against cross origin).
Here is a sample code, I think it should work (but it is not):
<!doctype html> <html> <head> </head> <body> <iframe id="myIframe" src="http://www.domain.com/"></iframe> <script src="jquery.min.js"></script> <script> $('#myIframe').on('load',function() { alert('Loaded correctly'); }); $('#myIframe').on('error',function() { alert('Load failed!'); }); </script> </body> </html>
I have no way to add code to a remote domain or upload a jsonp file, so AJAX / JSONP tricks are not possible (as far as I know).
source share