Question

Is it possible to give custom message for buttons instead of Cancel/Ok and give my own text?

I saw lots of tutorials on replacing js confirm with jquery dialog. But isn't there a way with using native JS? I see the same thing done in Grooveshark and many other pages; when user wants to navigate away from their page user is prompted with a js dialog box with custom buttons like 'Stay on page/Leave page'?

Any idea how they might be implementing this? Their dialog box appears as if generated using native JS!

Was it helpful?

Solution

I believe you were seeing a slightly different dialog box.

Add this to your page:

window.onbeforeunload = function() {
    return "Are you sure you want to navigate away?";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top