首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js监听封闭浏览器

2012-10-08 
js监听关闭浏览器script typetext/javascriptwindow.onbeforeunload function() //author: meizz?{

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"));

}

}

热点排行