Richard H
Richard H

Reputation: 39055

Check if window.onbeforeunload has been triggered by a page refresh?

I have a function like this to prompt the user to confirm they want to navigate away from the page:

window.onbeforeunload = function() {
   return "You may lose any unsaved changes.";
};    

Now I'd like to check whether this is a just a page refresh (F5), and not render the message in this case. Is this possible?

Thanks

Upvotes: 2

Views: 1395

Answers (1)

Sarfraz
Sarfraz

Reputation: 382696

Nope, that's not possible, there is no way to find out if the refresh button of browser was pressed.

Upvotes: 3

Related Questions