Stop iframe from loading

前端 未结 3 1684
一生所求
一生所求 2021-02-19 06:28

So i have iframe and i\'m uploading files through it, so my question is how can i stop it in the middle of the loading? I\'ve tried to change src with jquery function attr

3条回答
  •  终归单人心
    2021-02-19 06:59

    I believe the following answers your question: https://stackoverflow.com/a/2207589/1157493

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

    If you'd like the iframe to go to a different page you could try to redirect it to "about:blank"

提交回复
热议问题