Despite of JavaScript located in ASP.NET Core Page (cshtml), getting always a default message like "Changes Are Made..." from EDGE Browser (or CHROME is the same). Is there a way to use Custom Message?
window.onbeforeunload = function confirmExitPage() {
event.preventDefault();
return "My Custom Message I like to Show?";
}
I have already seen similar questions in SO, but none of them supplies a solution...
EDIT
Browsers absolutely prevent User Custom Message, reasonably. Then decide when this compulsory message should be issued to user:
<body>
<button onclick="activateReloader()">activate</button>
<button onclick="deactivateReloader()">deactivate</button>
<script>
function onBeforeUnload(e) {
e.preventDefault();
alert("my custom message");//this not works, for demo only
e.returnValue = '';
}
function activateReloader() {
window.addEventListener('beforeunload', onBeforeUnload);
}
function deactivateReloader() {
window.removeEventListener('beforeunload', onBeforeUnload);
}
</script>
</body>
This code states when message will be displayed to the user and when not.
preventDefault()on the event."event.preventDefault()but still same message Changes you made may not be saved.