Question

As many people, I tried to look for a solution to customize the onbeforeunload pop up window but I came up with no solution So I was wondering, is it possible to hide this onbeforeunload (or make it not appear) and make a custom alert/pop up doing the same and customized?

Was it helpful?

Solution 2

Onbeforeunload is a pain in th a** so I can of modify it (just the message) or know when it going to be fired (like clicking a button that goes to other page) and with javascript, disable it ( = null) and make a custom div that was hidden appear to look like a pop up.

OTHER TIPS

You can't do that, if you add an alert to the onbeforeunload event that will give you a confirm message. if you were to stop that from happening, the page would just close no matter what you put there instead.

all you can do is add a message to the alert which is displayed when asking if you want to stay on the page or leave, even then that is ignored in some browsers.

function promptMessage() {
        return "==============================\n\nINFO!!\n\n Please wait on this page until bla bla etc.\n\n==============================";
          }
window.onbeforeunload = promptMessage;

The reason you can't and never will be able to do this is because it allows the site owner to stop someone from leaving or bombarding the end user when they try to leave. Really, its a good thing that this is not allowed.

Myself, I do use onbeforeunload when a user has entered information into a form for example but has not saved that information when they try to leave or click on a link...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top