仅在IE中我在加载包含javascript的网站时收到警告,说明它导致页面运行缓慢(并询问我是否要阻止它)。
我已经看过其他关于此的帖子,我已经找了任何长时间运行的代码或无限循环等等。奇怪的是,当我选择'否'时(到不终止脚本) )页面立即正确加载。它几乎就像这个警告在页面加载完成之前出现。有没有人经历过这个,或者知道为什么会发生这种情况?
答案 0 :(得分:1)
答案 1 :(得分:0)
改编自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()