davej Posted August 18, 2013 Share Posted August 18, 2013 Why does it seem that an iframe will not generate an error event? Images generate error events and also with an image there is a complete property that can be re-checked later. Iframes do not seem to have such a property. An iframe will produce an onload event, but seemingly nothing else, so do you just start a timer and declare an error if onload has not been seen after some period of time? A error is visible inside the iframe, but programmatically I don't know how to detect it. http://www.w3schools.com/jsref/dom_obj_frame.asp <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>load errors</title><style>#iframe1,#img1{width: 400px;height: 300px;display: block;float:left;margin: 5px;border: 1px solid black;}</style><script>window.onload = init;function init(){document.getElementById('out').innerHTML = '';test();} function test(){var im = document.getElementById('img1');var ifr = document.getElementById('iframe1');var im_url = "xyz123.jpg";var if_url = "xyz123.html";im.onload = success; //assign handlerifr.onload = success; //assign handlerim.onerror = pferror; //assign error handler(s)ifr.onerror = pferror; //assign error handler(s)ifr.oninvalid = pferror;ifr.onabort = pferror;ifr.onemptied = pferror;ifr.onsuspend = pferror;im.src = im_url;ifr.src = if_url;}// end of funcfunction success(){document.getElementById('out').innerHTML += this.src + ' -----has been loaded<br/>';}// end of funcfunction pferror(){document.getElementById('out').innerHTML += this.src + ' -----load error occurred<br/>';}// end of func</script></head><body><div id="out"></div><iframe src="" id="iframe1"></iframe><img src="" id="img1" alt="img1"/></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted August 19, 2013 Share Posted August 19, 2013 It might be more effective to attach events to the iframe's contentWindow or contentDocument properties, which represent the window and document objects of the hosted content. Link to comment Share on other sites More sharing options...
davej Posted August 19, 2013 Author Share Posted August 19, 2013 (edited) Good point! I don't think I've tried that. Update: Nope, that didn't work either. Edited August 20, 2013 by davej Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now