Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2010, 12:04 PM
Authorized User
 
Join Date: Apr 2008
Posts: 35
Thanks: 1
Thanked 0 Times in 0 Posts
Default Leaving a WebPage ... sure?

I have been looking around today for a working example of code, which I can use in my HTML page to capture when a user has clicked the [X] at the top right, or has clicked to go to another website.

All of the examples which I have found use the onbeforeunload to pop a "Are you sure?" box, which is great, except that we're then prompted everytime we navigate from one page to another or perform a postback.

Can anyone advise either how I can just capture when the user is closing the browser or navigating to a page away from my domain?

Much appreciated.
__________________
Regards,

Sean
 
Old November 9th, 2010, 12:26 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In short no, the browser is fairly stateless and can't differentiate between the two.
You could add code to every link that sets a variable, e.g. isLinking to true, it would be initially set to false. You could then test this variable in the onbeforeunload handler.
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Webpage template help surendran Classic ASP Basics 2 June 8th, 2007 11:12 AM
print a webpage debjanib ASP.NET 2.0 Professional 1 January 1st, 2007 01:07 PM
change namespace leaving prefix unchanged lantoli XSLT 3 June 26th, 2006 07:31 AM
leaving blank text box in form when inserting data saif44 ASP.NET 2.0 Professional 1 March 9th, 2006 07:29 AM
Printing webpage rajanikrishna HTML Code Clinic 1 February 2nd, 2005 09:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.