-2

Is there any way in javascript to deactivate a button is the current page is refreshing / reloading? I want to deactivate some buttons when the user presses F5 / Refresh the page and I don't know if there is any way to verify is this event is ongoing. I want to add this validation when the user clicks the button:

<button onclick="if(IS_REFRESH_ONGOING) return false;">Button</button>
John R.
  • 420
  • 4
  • 14

1 Answers1

0

Use the beforeunload Event.

window.addEventListener("beforeunload", ()=>{
   // Add your disable button code here
});
Jamie Phan
  • 796
  • 1
  • 7
  • 26