本文介绍了浏览器关闭-代码未完全执行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在IE中创建了一个程序.
OnBeforeUnload或OnBeforeClose代码用于关闭数据库连接并更新一些内容.
当用户点击浏览器的X按钮时,这些代码永远不会完全完成.
除非我放置一个Alert(");它将无法完成代码.

有谁知道解决这个问题的方法吗?我已经坚持了很长时间,在任何地方都找不到任何帮助.:confused:

谢谢

Hi, I have created a program in IE.
OnBeforeUnload or OnBeforeClose code is used to close database connection and update a few things.
The code for these never finishes fully when the user hits the X button of the browser.
Unless i place an Alert(""); then it will not finish executing the code.

Does anyone know a way around this? I have been stuck on this for so long and cant find any help anywhere.:confused:

Thanks

推荐答案

function beforeClose(){
    if(inputChanged){
        // ... save data here
        return 'Are you sure you want to navigate away?';
    }
}



上面也看起来有点用户友好.我也正在考虑其他事情,但是我没有对此进行测试.这个想法是设置一个计时器并返回false,然后让Timer事件处理页面的保存和关闭.如果已经完成保存,您可能需要一个全局变量来跟踪,否则关闭将永远无法进行.



Above also looks kind of user friendly. I also was thinking about something else but I haven''t tested this. The idea is to setup a timer and return false and let the timer event handle the saving and closing of the page. You probably will need a global variable to keep track if saving is already done, otherwise closing will never work.

var isSaved = false;

<body onbeforeunload="if (!isSaved) {setTimeout(''handleWindowClose();'',50);return false;}">

function handleWindowClose()
{
  // Save data
  isSaved = true;
  // Close window
}




祝你好运!




Good luck!


这篇关于浏览器关闭-代码未完全执行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:33