Stopping a iframe from loading a page using javascript

前端 未结 6 533
情话喂你
情话喂你 2020-12-01 12:36

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

6条回答
  •  失恋的感觉
    2020-12-01 13:12

    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();
    }
    

提交回复
热议问题