ok, first of all i am not really sure what you want to do, but there is a event that occurs when you close the window.. and that is:
<BODY onUnload="function()">
Actually, this is not correct. There might bee a event named onunload (small-case is proffered after my knowledge), but the event onbeforeunload is triggered before that (I don't know the difference though, but my guessing is that onbeforeunload is triggered before the DOM-model is destroyed). Not saying that onunload is wrong, but it's not the only event triggered at browser close|redirect|refresh|++ At work we use onbeforeunload to save changes and it's confirmed working in all the browsers (though it's an ugly hack).
if you want to check if the F5 button on the keyboard is pressed try something like:
document.onkeydown=keyaction;
function keyaction(e)
{
if(!e)e = window.event;
alert(e.keyCode);
switch(e.keyCode)
{
case 63:function()
}
}
i don;t remember what is the code for F5, try that code and check it out...
if you want to occur only if the X or refresh button is press, i don;t know how to do that...
another thing that you should know is that such a event when you are closing the window/site is annoying sometimes, at least the one you put in the test
This might be true, it might be called when F5 is pressed, but I think this is browser-based, though not sure about that. Though what I do know is that handling onbeforeunload is somewhat difficult.
Here's what I'dd do:
<html>
<head>
<script language="javascript">
var isWarnUser = false;
function on_unload()
{
if(isWarnUser)
return " ";
isWarnUser = true;
}
</script>
</head>
<body onbeforeunload="return on_unload();">.....</body>
</html>
Last edited by Alxandr; Nov 4th, 2009 at 6:58 pm.
Reputation Points: 15
Solved Threads: 10
Junior Poster in Training
Offline 73 posts
since May 2009