0
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。卸載不工作在IE9和FF4
任何人都可以建議什麼是onunload的問題是有解決方案可靠地發送數據時瀏覽器關閉和onunload如何在所有瀏覽器中一致工作?
要求: 在瀏覽器關閉時顯示警告消息。 僅在瀏覽器確實關閉時才發送數據。 onbeforeunload方法返回用於顯示默認警告。警報將工作,但不會作爲一個警告消息與確定和取消選項。 – user751674 2011-05-13 14:25:46