Stopping a iframe from loading a page using javascript Stopping a iframe from loading a page using javascript javascript javascript

Stopping a iframe from loading a page using javascript


For FireFox/Safari/Chrome you can use window.stop():

window.frames[0].stop()

For IE, you can do the same thing with document.execCommand('Stop'):

window.frames[0].document.execCommand('Stop')

For a cross-browser solution you could use:

if (navigator.appName == 'Microsoft Internet Explorer') {  window.frames[0].document.execCommand('Stop');} else {  window.frames[0].stop();}


The whole code should be like this, (unclenorton's line was missing a bracket)

if (typeof (window.frames[0].stop) === 'undefined'){    //Internet Explorer code    setTimeout(function() {window.frames[0].document.execCommand('Stop');},1000);}else{    //Other browsers    setTimeout(function() {window.frames[0].stop();},1000);}


Merely,

document.getElementById("myiframe").src = '';