Is there a way in javascript of stopping an iframe in the middle of loading a page? The reason I need to do this is I have a background iframe streaming data from a web serv
If you only have a reference to the element, you need to use .contentX to get the document/window to run the accepted answer.
Checking that the iframe actually has a document is also necessary for dynamically added iframe elements.
function stopIframe(element) {
var doc = element.contentDocument;
//iframes wont have a document if they aren't loading/loaded
//check so JS wont throw
if (!doc)
return;
//try for modern browsers
if (doc.defaultView.stop)
doc.defaultView.stop();
//fallback for IE
else
doc.execCommand('Stop');
}