Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<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>



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..
Posted
Comments
walterhevedeich 26-Nov-13 0:12am    
I think it does what it's supposed to do. What is your issue here?
Rayan Khan 26-Nov-13 2:11am    
well when in trying ot move to some other site using url it show window close alert..

1 solution

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.
 
Share this answer
 
Comments
Rayan Khan 27-Nov-13 3:36am    
i want javascript code which will alert only when user close the window only,not when user refresh or move to other site by giving new address in address bar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900