var unloadOK = "false";//used as variable when data need to be send to the server
window.onbeforeunload = CheckBeforeUnload;
window.onunload = CheckUnload
function CheckBeforeUnload(){
document.getElementById("ContentPlayer").CheckUnload("");
return "Are you sure you want to exit?"
}
function CheckUnload(){
unloadOK = "true";
pause(1000);
alert("session saved");
}
function pause(millis)
{
var date = new Date();
var curDate = null;
do {
curDate = new Date();
} while(curDate-date < millis);
}
以上是代码:当用户尝试关闭浏览器时,我正在尝试发送数据。
Onunload 方法在 IE7 和 IE8 中有效,但在 IE9 和 FF4 中无效。应用程序内置在 Flex 3.0 sdk 中。
谁能建议 onunload 有什么问题,是否有解决方案可以在浏览器关闭时可靠地发送数据以及 onunload 如何在所有浏览器中始终如一地工作?