Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a page, when user going to close this page, here I want to call a method in javascript. For this I used onunload method in javascript. Here I want to check whether the user is going to close a page or move to another page. If he is navigating to another page I want to stop the execution of this program otherwise need to open another page using window.open method.

Please let me know how to check whether the user is going to close a page or moving to another page??
Posted
Updated 28-May-12 4:01am
v2

1 solution

You can't. onunload is called when the user leaves your page, and it doesn't contain any extra information that tells you where they've gone (understandably, since that would be a major privacy issue).

What are you actually trying to do? What you've asked for sounds like a usability nightmare. I suspect the correct answer to this question is to redesign your website so it acts like a website.
 
Share this answer
 
Comments
Dylan Morley 28-May-12 10:30am    
Agreed. Also, nothing you can possibly do in javascript will be reliable, since I can just disable script.

Sounds like horrible javascript tricks to try and keep users on your site and spam them with popup windows!

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