`

js监听关闭浏览器

 
阅读更多

<script type="text/javascript">

window.onbeforeunload = function() //author: meizz 

    window.location="http://localhost:8080/tt/servlet/tt?action=loginOut";

alert("关闭窗口之前"); 

  

}

window.onunload = function() //author: meizz 

alert("关闭窗口"); 

  

}

</script>

 

 

String action = request.getParameter("action");

   HttpSession session = request.getSession();

if("login".equals(action))

{

    if(null == session.getAttribute("flag"))

    {

        session.setAttribute("flag", 1);  

    }

    System.out.println("login \t:"+  session.getAttribute("flag"));

    

}

else if("loginOut".equals(action))

{

session.removeAttribute("flag");

System.out.println("loginOut \t:"+  session.getAttribute("flag"));

}

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics