本文介绍了如何在浏览器关闭按钮事件上编写代码..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在浏览器关闭按钮事件上编写代码.我想注销用户并更改其在数据库中的状态,即使他单击浏览器的关闭按钮也是如此.
感谢adv
how to write code on browser close button event .. i want to log out user and change his status in Database even if he hit the close button of the browser.
Thanks in adv
推荐答案
<body onunload.</code><br />
check out which one suits you..
<script type="text/javascript" language="javascript">
window.onbeforeunload = function(event)
{
var msg = 'Are you sure you want to leave?';
if (((window.event.clientX || event.clientX) < 0) || ((window.event.clientY || event.clientY)<0)) // close button
{
event=window.event;
event.returnValue = msg;
return msg;
}
if ((window.event.clientX < 0) || (window.event.clientY<0)) // close button
{
event=window.event;
event.returnValue = msg;
return msg;
}
else if (window.event.altKey == true || window.event.ctrlKey == true) // ALT + F4
{
event=window.event;
event.returnValue = msg;
return msg;
}
else // for all other unload events
{
}
}
</script>
这篇关于如何在浏览器关闭按钮事件上编写代码..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!