Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
705 views
in Technique[技术] by (71.8m points)

jquery - onBeforeUnload custom button messages

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

$().ready(function() {
    $("#posManagerLoginForm").trigger("submit");

    $(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?

thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Reference: http://msdn.microsoft.com/en-us/library/ms536907%28VS.85%29.aspx

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...