Richie Richie - 3 months ago 23
jQuery Question

onBeforeUnload custom button messages

I have the following beforeunload function which I have stolen from sonewhere else....

$().ready(function() {

$(window).bind("beforeunload", function(){
window.setTimeout(function () {
window.location = "home.htm";
}, 0);
window.onbeforeunload = null; // necessary to prevent infinite loop that kills your browser
return "Press 'Stay On Page' to go to Reporting Manager home";

Regardless of what option I select I get navigated to home.htm. Is there a way that I can make the dialog box an ok button instead of the default "Leave Page" or "Stay on page" options?

Or perhaps someone else could make a suggestion on hot to better handle?



You cannot override the styling of the onbeforeunload dialog. Believe me, I tried this before in my earlier projects.


It is built into the browser object, and you have no control over it.

You can however set your own dialog to show when the onbeforeunload event triggers, but it will not disable that the regular one will show. Quite annoying, yes.