Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onUnload and window.close

Status
Not open for further replies.

stevelazow

Programmer
Feb 12, 2007
2
0
0
US
I am trying to execute some javascript code only when a window is closed, but not when there is a transition from one page to another. onUnload is the same for both. Is there something that I can access that changes when a user closes the window, but not when he page just changes?
 
Not inherently no.

You can however, set up your links so that they switch a global variable from true to false when clicked.
eg:
Code:
var runCloseCode = true;
Code:
<a href="somepage.html" onclick="runCloseCode=false;">Linky</a>

Then you can check to see if [tt]runCloseCode[/tt] is still true when the page unloads. If it is, most likely they've closed their window or typed in a new address and you can run your code begging them to stay on your site or fill in your survey etc.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top