This topic is locked
[SOLVED]

 Popup when leaving or exiting a page - Have you Saved !

2/26/2012 11:25:51 AM
PHPRunner General questions
A
Athlon author

Is it possible to do this using javascript: I am having little success. I dont want to use a field name if possible but page dirty. However I do have a last update field I could use as a var in pageID.
User enters lots of information - closes browser or leaves page before saving - loses all data .. Is happening a lot with my clients.
I understand different browsers run different scripts, but think it should really be good practice (Standard) in any database app used online if possible. None of them seem do this by default, but clearly this is a huge issue for users, especially non experienced.
It would be beneficial to have a popup display where they are prompted to cancel action and save changes.
Thanks in anticipation.

A
Athlon author 2/26/2012



http://stackoverflow.com/questions/4067796/how-to-create-popup-window-when-browser-close


Thank you, However I was still in the same situation. Onload does not seem to work or function at all. I maybe was looking up the wrong tree or have not understood the function correctly. window.onclose does nothing either for me. no errors etc..
I solved it pretty easily in the end using the following code included as I think it will help other newbies.
Added in the Javascript Onload event for the page in question.
window.onbeforeunload = function (evt) {

var message = 'Are you sure you have SAVED YOUR ENTRIES before exit?';

if (typeof evt == 'undefined') {

evt = window.event;

}

if (evt) {

evt.returnValue = message;

}

return message;

}
Fires if a close tab, window or leave a page happens. Prevents data on the page being lost.