Thursday, June 6, 2024
 Popular · Latest · Hot · Upcoming
143
rated 0 times [  144] [ 1]  / answers: 1 / hits: 18929  / 13 Years ago, tue, december 20, 2011, 12:00:00

I'm developing one of those warning windows that tells the user that they may have unsaved data, but I only need it to warn them if they're leaving the page. Currently it does so on refreshes, postbacks, etc. I was wondering if there was any way to tell how the page was unloaded or otherwise get more details about what the user is doing to unload the page. (jquery solutions welcome).



Code for reference:




window.onbeforeunload = function () {
if (formIsDirty) {
formIsDirty = false;
return Are you sure you want to navigate away from this page?;
}
}

More From » jquery

 Answers
14

on beforeunload event we can do below things:




  1. We can pass event as a parameter to the function as in above answer.
    Now we can use this event for available information attached to this
    event.

  2. And we can access Document level variables.



For example document.activeElement will give you the last element you clicked that caused the page unload.



Hope this helps!!


[#88460] Monday, December 19, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
billie

Total Points: 101
Total Questions: 114
Total Answers: 98

Location: Burundi
Member since Wed, Nov 25, 2020
4 Years ago
billie questions
;