卸载在 IE9 和 FF4 中不起作用

发布于 2024-11-07 02:58:46 字数 754 浏览 4 评论 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 中构建的。

任何人都可以建议 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿童谣 2024-11-14 02:58:46

上面是代码:我正在尝试发送
用户尝试关闭时的数据
浏览器。 Onunload 方法在 IE7 中工作
和 IE8,但不包括 IE9 和 FF4。
应用程序是在 Flex 3.0 sdk 中构建的。

不确定这有多重要,但尝试在将函数调用分配为处理程序之前放置它们。

function CheckBeforeUnload(){
  document.getElementById("ContentPlayer").CheckUnload("");
  return "Are you sure you want to exit?"
}

您可能需要这里的 alert() 而不是 return

任何人都可以提出问题是什么
onunload 有没有解决方案
当浏览器打开时可靠地发送数据
关闭以及 onunload 如何工作
在所有浏览器中一致?

不幸的是,用户可以简单地关闭页面所在的选项卡并绕过它。他们还可以使用 Google Chrome 的进程监视器来终止该选项卡。最后,他们可以强制退出应用程序。依赖此功能作为最终解决方案是很糟糕的。

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.

Not sure how much it will matter, but try putting the function calls before you assign them as handlers.

function CheckBeforeUnload(){
  document.getElementById("ContentPlayer").CheckUnload("");
  return "Are you sure you want to exit?"
}

You probably want an alert() here instead of a return

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?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文