只有在IE浏览器中,当我加载包含javascript的网站时,它会导致页面运行缓慢(并询问是否要停止它),我得到一个警告。IE停止脚本警告
我见过有关这个的其他帖子,我找过任何长时间运行的代码或无限循环等等。奇怪的是,当我选择'否'(而不是终止脚本)页面立即正确加载。它几乎就像这个警告出现在页面加载完成之前。有没有人经历过这个,或者知道为什么会发生这种情况?
只有在IE浏览器中,当我加载包含javascript的网站时,它会导致页面运行缓慢(并询问是否要停止它),我得到一个警告。IE停止脚本警告
我见过有关这个的其他帖子,我找过任何长时间运行的代码或无限循环等等。奇怪的是,当我选择'否'(而不是终止脚本)页面立即正确加载。它几乎就像这个警告出现在页面加载完成之前。有没有人经历过这个,或者知道为什么会发生这种情况?
从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()
改编什么是做网页上的代码?细节总是很好。 – epascarello 2010-08-12 16:05:04