2

I am calling this code by this window.onbeforeunload=HandleOnClose;

This is working fine in IE but not in other browsers. This code is specific for IE but this is not working in other browsers. How can we detect close event of browser in all the browser ?

function ConfirmClose()
    {
        if (isIE7Min) //To check for IE Version 7.0 and above
        {   
          var n = window.event.screenX - window.screenLeft; 
          var b = n > document.documentElement.scrollWidth-20;
            if ((b && window.event.clientY < 0) || window.event.altKey) 
            {
                if (!self.closed)
                {
                    refresh = true;
                }
            }
        }
        else   //IE Version 6.0 and below
        {
            if (event.clientY < 0 && event.clientX < 0)
            {
                if (!self.closed)
                {
                    refresh = true;
                }
            }
        }
    }

    /*Function for onunload*/

    function HandleOnClose()
    {

        ConfirmClose();

        if (isIE7Min)
        {

            if ((window.event.clientX > 0 && window.event.clientY < 0) || window.event.altKey) 
            {
                if (refresh == true) 
                {           
                    window.open("/DealPricingJavaUAT/DealPricingJsp/Home/logout.jsf");
                    //Code That redirects to the Session Invalidation Page
                }
            }
        }
        else
        {

            if (event.clientY < 0 && event.clientX < 0 || window.event.altKey)
            {
                if (refresh == false) 
                {                      
               window.open("/DealPricingJavaUAT/DealPricingJsp/Home/logout.jsf");
                // Code That redirects to the Session Invalidation Page    
                }
            }
        }
    }
4

2 回答 2

1

我认为不可能总是注销用户。如果用户的网络浏览器崩溃,客户端代码将永远不会被执行。一些 Web 浏览器会非常快地自行关闭,并且不会等待执行客户端代码。

您应该找到替代解决方案,例如如果用户在一段时间内不活动,则在服务器端注销。

于 2012-09-25T10:46:46.200 回答
0

无法检测到用户何时关闭浏览器。如果您使用 java 并使用 cookie 来检查用户是否已登录,则可以执行 cookie.setMaxAge(-1)。

这将确保在浏览器关闭时删除 cookie。

于 2012-09-25T10:56:20.533 回答