Stop iframe from loading

前端 未结 3 1683
一生所求
一生所求 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"

    0 讨论(0)
  • 2021-02-19 07:18

    This works for me (IE, Chrome, FF, Opera):

    $iframe.attr('src','about:blank');
    
    0 讨论(0)
  • 2021-02-19 07:23

    can use this for disabling all iframe content

    <script>
        var frames = window.frames;
        var i;
    
        for (i = 0; i < frames.length; i++) {
            frames[i].location = "";
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题