Reputation: 5620
I want to handle window.onbeforeunload event. I can handle it this way
window.onbeforeunload = function() {
return "MSG";
}
But in this case it shows a popup asking for user confirmation i dont want that confirmation dialog instead it will directly return false
like event.cancel = true
.
Upvotes: 0
Views: 1911
Reputation: 3018
You cannot do this in the onBeforeUnload. The for this reason is; the user has already sent in a request to move away from the page and the event has been intercepted. The confirm is the best you can do, unless you prevent the event further up the event chain (such as with onkeydown).
For instance, if you want the user to not be able to use their keyboard to go backwards and forwards in history, or to reload the page, this could be achieved using;
var catchKey = {
37: true, /// left
39: true /// right
};
window.onkeydown = function(event) {
if (catchKey[event.keyCode] && event.ctrlKey) {
event.preventDefault();
event.stopPropagation();
}
}
Hope that helps!
Upvotes: 1
Reputation: 54
Basically you want to prevent the user from closing the browser window/tab or navigate away from your page at all?
I am sure no browser maker will let you do that... then the only way to close the browser in such a case would be to kill the process.
So: Not possible, as far as I can see.
Upvotes: 0