Mohan
Mohan

Reputation: 385

close the tab by asking a confirmation box in react js

I'm trying to add this custom message using the below code but it's showing the default message. please help me where I'm doing wrong thanks in advance

enter image description here

window.addEventListener("beforeunload", (ev) => {  
 ev.preventDefault();
 return ev.returnValue = 'Are you sure you want to close?'; 
});

Upvotes: 0

Views: 1217

Answers (1)

Greg
Greg

Reputation: 6628

This dialog looks like chrome, and chrome removed the option to customize this message, see here: https://developers.google.com/web/updates/2016/04/chrome-51-deprecations?hl=en#remove_custom_messages_in_onbeforeunload_dialogs

Also this answer claims it's not only chrome, but most browsers https://stackoverflow.com/a/38880926/299774

Upvotes: 1

Related Questions