2

I want to have the confirmation dialog box from the browser only when browser/tab is closing or refresh is clicked.

Currently I use the following code but it beforeunload is triggered even when the it's redirected to another page. I have a form and once the form data is submitted, the url is changed. I don't need the confirmation dialog box (with the text "Changes you made may not be saved.") to be visible everytime users click submit the form.


useBeforeunload(() => {
return "Are you sure you want to leave?";
});
  • Did you try this [javascript-beforeunload-detect-refresh-versus-close](https://stackoverflow.com/questions/11453741/javascript-beforeunload-detect-refresh-versus-close)? – FerdousTheWebCoder Apr 19 '21 at 11:19

0 Answers0