窗口关闭处理程序 [英] window close handler

查看:67
本文介绍了窗口关闭处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<body onbeforeunload="doUnload()" onmousedown="Relode()">
<form id="form1" runat="server">
</form>
</body>
<script language="javascript" type="text/javascript">
var isClose = false;
document.onkeydown = checkKeycode
function checkKeycode(e) {
var keycode;
if (window.event)
keycode = window.event.keyCode;
else if (e)
keycode = e.which;
if(keycode == 116)
{
isClose = true;
}
}
//This code will take care of refresh/rerlode by right click or F5//// Designed by Nawab Ahmad on 25112013.......
function Relode()
{
isClose = true;
}
alert("relode")
//This code is responsible for close window handler//// designed by Nawab Ahmad on 25112013......
function doUnload()
{
if(!isClose)
{
alert('window is closing');
}
}

////Tested on IE 6,7,8,9,10.....
</script>







此代码工作正常,但是当我试图通过从同一个窗口窗口输入新的addree来移动到另一个站点时关闭警报正在进行..




This code is working fine but when i m trying to move to another site by entering new addrees in address from same window window close alert is comming..

推荐答案

我认为当你改写URL时,表单会触发unload事件,从而产生警告信息。这是一种普遍现象。如果您能告诉我们完整的要求,我们可以留意一下。我的意思是,我们需要知道你想要实现的目标。
I think when you overtype the URL, the form is firing the unload event resulting in the alert message. This is a common phenomenon. If you can let us know the complete requirement, we can lookout for a work around. What I meant is, we need to know what you are trying to achieve.


这篇关于窗口关闭处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆