Search code examples
javascriptbrowsergmail

How to customize confirm() popup text like Gmail does?


In Gmail when you are in middle of composing a email and attempt to navigate away from the page they pop up a confirm() dialog box The first line of the box is "Reload site?"

However when I use confirm('message') in the popup that is generated the first line of text always contains the text localhost says

From what I have seen the confirm() only has one parameter message

How is Gmail able to customize that text to say Reload site?


Solution

  • Gmail uses window.onbeforeunload which bypasses the security restriction of showing the sites domain and instead replaces it with a context specific header.

    window.onbeforeunload = () => 'some message'