卸载在 IE9 和 FF4 中不起作用
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 如何在所有浏览器中一致地工作?
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);
}
Above is the code: I am trying send data when user trying to close the browser.
Onunload method work in IE7 and IE8 but not in IE9 and FF4.
Application is built in Flex 3.0 sdk.
Can anyone suggest what is the issue with onunload is there solution to send data reliably when browser is closing and how onunload work consistently in all browser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这有多重要,但尝试在将函数调用分配为处理程序之前放置它们。
您可能需要这里的
alert()
而不是return
不幸的是,用户可以简单地关闭页面所在的选项卡并绕过它。他们还可以使用 Google Chrome 的进程监视器来终止该选项卡。最后,他们可以强制退出应用程序。依赖此功能作为最终解决方案是很糟糕的。
Not sure how much it will matter, but try putting the function calls before you assign them as handlers.
You probably want an
alert()
here instead of areturn
Unfortunately a user can simply close the tab your page is on and circumvent it. They could also use, say, Google Chrome's process monitor to kill the tab. Finally, they can force quit the application. It's bad to depend on this functionality as the end all solution.