开发者

IE stop script warning

Only in IE I get a warning when loading my site containing javascript saying that its causing the page to run slowly (and asking if I want to stop it).

开发者_如何学Python

I've seen other posts about this and I've looked for any long running code or infinite loops etc. The weird thing is, when I select 'No' (to not terminate the script) the page immediately loads properly. Its almost like this warning comes up right before the page is done loading. Has anybody experienced this, or know why this might be happening?


IE has its own way of making your life impossible.

Just deactivate the warning, you can further research in the future if that's necessary.

This article might help you determine why IE is giving such a warning.

Regards,


Adapted from http://www.codeproject.com/Tips/406739/Preventing-Stop-running-this-script-in-Browsers

// Magic IE<9 workaround for irritating "Stop running this script?" dialog.
RepeatOperation = function(anonymousOperation, whenToYield){
    var count = 0
    return function(){
        if (++count >= whenToYield){
            count = 0
            setTimeout(function(){anonymousOperation()}, 100)
        }
        else anonymousOperation()
    }
}

// How to implement the workaround:

//for (var i in retailers){ // Too big for IE<9! Use magic workaround:
var i = 0; var noInArray = retailers.length
var ro = new RepeatOperation(function(){

    // <<Your loop body here, using return instead of continue.>>

    if (++i < noInArray) ro()
    else alert("Loop finished.")
}, 200) // Run this in batches of n. 500 is too much for IE<9.
ro()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜