Internet Explorer上的异步消息
问题描述:
我试图解决一个问题。基本上我需要在长时间运行的Javascript代码中显示“加载消息”,并在代码结束时将其隐藏,因此类似于:Internet Explorer上的异步消息
showMessage();
executeMyCode();
hideMessage();
但是,我在使用Internet Explorer时遇到了问题,现在看起来好像页面被冻结,直到所有脚本代码完成,这可能会让用户感到烦恼。我尝试过使用setTimeout()方法,但这不起作用,你有没有解决这个问题?我很感谢你的帮助。
在此先感谢。
答
你可以做这样的事情:
function showMessage(){
/* show message */;
window.delay=setTimeout(executeMyCode,100); // Give some time to browser to render message
return;
}
function executeMyCode(){
clearTimeout(window.delay);
/* execute long running code */
/* hide message */
return;
}
虽然浏览器将仍然被冻结,而执行长码,用户现在可以看到的消息。