homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

onbeforeunload help!

 5:11 pm on Apr 1, 2009 (gmt 0)

i am new to javascript, so thanks in advance. i've created a form for a user to complete, but i want to warn them if they leave the particular page without completing the form. i've added onbeforeunload, but the warning appears even when the page is refreshed, which is not what i want.

is there any way to check in javascript whether the next requested page equals the current page (i.e. page refresh or a call to the same page)? location.href == ?




 5:46 pm on Apr 1, 2009 (gmt 0)

figured it out! i've added "onclick" to the button/link used when i do not want a warning to pop up. onclick calls a javascript function that sets a variable to true. only when that variable is false will the warning pop up.


 7:02 pm on Apr 1, 2009 (gmt 0)

another question... i have a page called contest.php that consists of 3 different "steps" of the competition, so essentially the page is recalled 3 times before the person has successfully entered the competition. if a person clicks away from this page, then they will receive the warning message. i would like to track how many people leave the contest prior to completing all the steps. can i do this with onunload by inserting into a database when the page is unloaded? if so, how would i insert into a mysql database onunload?



 7:57 pm on Apr 1, 2009 (gmt 0)

You can't use onunload like that. An alternative would be to track how many people hit each step. For example, user reaches first step, database is updated, user reaches second step, database is updated... etc. You can then track how many people reached the first step, up to n steps, and subtract from the n step to determine how many people quit and at which step.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved