Reputation: 2018
I am using the JavaScript method onunload
, but this is triggered when the page is close or navigated to another page or the back button is hit. Is there a way to differentiate between page closing and the back button being hit? I am using a combination of html JavaScript and PHP as the server side language.
Upvotes: 0
Views: 283
Reputation: 78741
As far as I know there is no way to differentiate between these. If you use onbeforeunload
as Gidon suggested, you can at least offer the user the choice whether he wants to stay on the current page or really leave and possibly lose data.
UPDATE: if you are playing around with iframes, it might be possible (though not surely cross-browser), found it here: http://www.tek-tips.com/viewthread.cfm?qid=1590281&page=25
Upvotes: 3