Search code examples
javascriptonbeforeunload

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


Solution

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