Welcome to WebmasterWorld Guest from 54.226.238.178

Forum Moderators: open

Message Too Old, No Replies

onbeforeunload help!

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

Junior Member

5+ Year Member

joined:Jan 23, 2007
posts:48
votes: 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 == ?

thanks!

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

Junior Member

5+ Year Member

joined:Jan 23, 2007
posts:48
votes: 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)

Junior Member

5+ Year Member

joined:Jan 23, 2007
posts:48
votes: 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?

thanks!

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

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts:4988
votes: 12


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members