javascript - jQuery: Detect iFrame not loaded after X sections -
i'm loading iframe in modal window domain, frame not load, or takes 20+ seconds load. here code:
html:
<div id="mask"> <div id="iframe_lightbox"> <div id="iframe_container"><iframe id="patterncooleriframe" style="width: 100%; height: 100%;" src="" frameborder="0" ></iframe></div> <div id="iframe_lightbox_close">x</div> </div> </div>
js:
function launch_iframe(iframesrc, iframeid){ $("#mask").fadeto('500', 1, function () { $('<iframe>', { src: iframesrc, id: 'iframeid', frameborder: 0, scrolling: 'no', width: '100%', height: iframeh+'px' }).appendto('#iframe_container'); }); }
how can detect if content has not loaded in iframe after x seconds? i'd either display message user, or refresh page.
you can use timer , check if onload
handler has fired
function launch_iframe(iframesrc, iframeid){ var timer = settimeout(function() { alert('the iframe didn\'t load in 5 seconds !'); }, 5000); $("#mask").fadeto('500', 1, function () { $('<iframe>', { src : iframesrc, id : 'iframeid', frameborder : 0, scrolling : 'no', width : '100%', height : iframeh+'px', on : { load : function() { cleartimeout(timer); // remove timer when iframe loads } } }).appendto('#iframe_container'); }); }
Comments
Post a Comment