/    Sign up×
Community /Pin to ProfileBookmark

Tracking manual browser closings

Here is a question that i cannot truely answer.

I have a survey page opened up with a javascript window.open(). However, if for somereason someone desides half way through the survey that they do not want to finish it and they hit the X at the top right corner to close the survey i would like to TRACK that. When the survey form is complete, the action goes to a PHP file and places it into a database.

If they close the browser on their own though i want it to put into the database as an INCOMPLETE. How could i code that?

Is this something that a <body unload()> would handle or what?

Anthony

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@VladdyApr 30.2004 — Forget about tracking browser closing. Set INCOMPLETE in DB when serving the survey.

Alternatively you can do the round trip on every question, filling the record with every answer....
Copy linkTweet thisAlerts:
@TheBearMayApr 30.2004 — What comes to mind is setting a variable at completion and then testing it's value with the onunload.

[code=php]
....
var reasonCode = "Incomplete";

function checkReason() {
if(reasonCode == "Incomplete") {
....
}
}


<body onunload="checkReason()">
...
<button onclick="reasonCode='Complete';submitSurvey();"> Submit</button>
....
[/code]
Copy linkTweet thisAlerts:
@AcemanauthorApr 30.2004 — OK guys, I liked the idea, but one problem with it. To have the information hit the database you must hit Submit so it runs the php file attaching info to database.

SO ... if they click the X and close the browser, how will it get stored in the database?

<body onunload="storedatabase()"> and have the function storedatabase be something like this:

function storedatabase() {

var reasonCode = "Incomplete";

src = databasesubmission.php;

}

? not sure how to code it opening that php file.

Anthony
Copy linkTweet thisAlerts:
@AdamGundryApr 30.2004 — The only reliable method is to use the method Vladdy suggested - initially mark the record as incomplete, then replace it if they submit the data. Onunload is unreliable, and what happens if their browser/computer crashses?

Adam
×

Success!

Help @Aceman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...