I have registration page, when user enters some details and click on refresh or back/forward button.Then we have to alert user with modal pop up like: "Are you sure want to leave the page". I've tried some but the alerts are showing in every page.I only need on registration page and no need to refresh alert messages in other pages.
I have added to this code to registration page
componentWillMount()
{
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';
myEvent(chkevent, function(e) {
var confirmationMessage = 'Are you sure to leave the page?';
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
}
How can i prevent the refresh alert message in other pages except registration page and how to add custom alert message in refresh/back/forward buttons.