/    Sign up×
Community /Pin to ProfileBookmark

Saving data when user clicks the "X" button

Hi all –

I am having a problem saving information if a user clicks the “X” and closes the window. I need data to be sent to a Learning Management System (LMS) regardless of whether a user exits a course properly or clicks the “X”.

The data is saved fine if the user exits properly. I’m having trouble with the “X” because I don’t know how to delay the window closing. I have data saved on a frame, and if the window closes too quickly, the data doesn’t have enough time to make it to the server.

Any ideas? I’m using JavaScript and HTML to build the course.

Any help is greatly appreciated! Thanks

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriFeb 03.2004 — i answered this the other day, let me find the thread
Copy linkTweet thisAlerts:
@crh3675Feb 03.2004 — I avoided this problem by having all changes update through an IMG src attribute.



<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
var wintitle=document.title; // Store Document Title
var curValue;

// Gets Object Value And Stores In Variable
function getVal(obj){
curValue=obj.value;
}

// Simply Displays Status
function winstat(text){
document.title=text;
window.status=text;
return true;
}

// Changes Image Src To Page That Processes Code
function runUpdate(qry){
document.getElementById("dbUpdater").src=qry; // Pass Entire Query String To Page For Update
winstat("Updating..."); // Change Window Status
setTimeout("winstat(wintitle)",350)
}

// Function To Accept New Field Value
function updateRecord(tableName,fieldName,fieldValue,recordID){
if (curValue!=fieldValue){
qry="yourpageto runcode.php?table="+escape(tableName)+"&amp;field="+escape(fieldName)+"&amp;value="+escape(fieldValue)+"&amp;id="+recordID
runUpdate(qry)
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form&gt;
&lt;input type="text" name="myField" onfocus="getVal(this)" onblur="updateRecord('myTable','myField',this.value,1)" size="55"&gt;
&lt;/form&gt;

&lt;!--This is our bogus image //--&gt;
&lt;img src="" name="dbUpdater" id="dbUpdater" width="1" height="1"&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@96turnerriFeb 03.2004 — try this

<body onunload="if(confirm('Have You Saved Your Work?')){return true;}else{return false;}">

change return false to the function of saving the work and then make it close, AFAIK this will not work in IE6 or Moz1.4 as its a browser security issue
Copy linkTweet thisAlerts:
@melendezpauthorFeb 05.2004 — Thank you all so much for the suggestions - I tried the suggestions, and it ended up I'd have to submit the data on the onLoad of every page for it to do what I needed it to. Your ideas helped me brainstorm and come with a great solution!

Thanks again!
Copy linkTweet thisAlerts:
@96turnerriFeb 05.2004 — submit date onload? why?
Copy linkTweet thisAlerts:
@VengeanceFeb 06.2004 — Hi all,

I was wanting to do something similar to this. Prevent the user from leaving an entry form whether by navigating away or by hitting the exit or cancel button. I had hoped to try and use something like the method you suggested with the onUnload but being that I'm running this in IE6, which you said wouldn't work' then what else can you suggest in ways to prevent a user from losing entered data?

Is there any way to override the shutting down or navigating away of a page? I would think not just due to how easily this could be abused.


TIA

Brian
Copy linkTweet thisAlerts:
@96turnerriFeb 06.2004 — you could send the form on unload as you said or get the info to store in a cookie so when they they return after leaving page accidently then the form will all ready be populated
×

Success!

Help @melendezp 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.19,
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,
)...