Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I'm designing an app but I want to know what event I should use for that an action will be done when I'll close the window.

I've tried with window.close but it does the action when I load/go to the website and no when i want to close it, that is what i want that it does.
Posted
Updated 10-Dec-10 11:36am
v7

This link will explain it including an example:

http://msdn.microsoft.com/en-us/library/ms536907.aspx[^]

Good luck!
 
Share this answer
 
Comments
Ángel Manuel García Carmona 10-Dec-10 17:38pm    
Sorry, but the event of the links that you has given me, does the action when i open/load the website and no when i want to close it.
E.F. Nijboer 10-Dec-10 17:45pm    
How do you mean? onbeforeunload and unload are fired when you leave/close the current page. The onload is fired when the page is opened and received completely.

Have a look at the list of events yourself:
DHTML Events: http://msdn.microsoft.com/en-us/library/ms533051%28v=VS.85%29.aspx

onunload: http://msdn.microsoft.com/en-us/library/ms536973%28v=VS.85%29.aspxon
Ángel Manuel García Carmona 10-Dec-10 18:23pm    
With this events, the action will be done when i load the page and no when i will close it
Dr.Walt Fair, PE 10-Dec-10 19:28pm    
I think you are confusing onunload and onload.
E.F. Nijboer 11-Dec-10 4:30am    
I agree with Wait Fair Jr. You can try the code example given and have a look at what it does:
http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onbeforeunload.htm
My problem was solved assigning the lines like a function (JAVASCRIPT).
The problem was in an ASPX page, and it was that with this method, the action ocurred when i loaded/opened the website and no when i closed it, but adding a function, i haven't problems (like in this block and the links that you has given me):
function closeIt() {
            alert('HI');
        }
        window.onbeforeunload = closeIt;

and no like this (like this i had the problem):
window.onbeforeunload = alert('Bye, bye');

Thanks very much for your help
Regards
 
Share this answer
 
v2

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