3

I know that most browsers have discontinued support for being able to customize the onbeforeunload message however I came across this message on the Google DoubleClick website. Is this because it's a google website and they can do whatever they want?

something as basic as

window.onbeforeunload = function () {return 'Custom message'} 

to using https://github.com/codedance/jquery.AreYouSure . I'm going to assume that because the custom message I see in the image above is on a ddm.google.com (google advertising platform) that they can override their own rules?

firefox onbeforeunload message custom onbeforeunload message

edited because How can I override the OnBeforeUnload dialog and replace it with my own? is no longer valid due to changes in chrome and other browsers

Community
  • 1
  • 1
gteh
  • 741
  • 10
  • 17
  • 1
    If you've found a site that can change it then why not looking into the site's code how they do it? – Radek Pech Apr 04 '17 at 07:32
  • 1
    What have u tried? And it might help you http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own – Muddu Patil Apr 04 '17 at 07:39
  • something as basic as window.onbeforeunload = function () {return 'Custom message'} to using https://github.com/codedance/jquery.AreYouSure. I'm going to assume that because the custom message I see in the image above is on a ddm.google.com (google advertising platform) that they can override their own rules? lol – gteh Apr 04 '17 at 07:44
  • 1
    What if you try this same page from a different browser ? – Kaiido Apr 04 '17 at 07:49
  • The message can be customised by returning a string from the `beforeunload` handler, but the look and behaviour of the dialog cannot. Google is not doing anything special here, neither does the library you linked to. – GregL Apr 04 '17 at 07:54
  • Possible duplicate of [How can I override the OnBeforeUnload dialog and replace it with my own?](http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own) – GregL Apr 04 '17 at 07:55
  • 2
    @GregL, you're a bit late http://stackoverflow.com/questions/37782104/javascript-onbeforeunload-not-showing-custom-message/37782307#37782307 – Kaiido Apr 04 '17 at 07:55
  • @Kaiido Huh. I didn't hear about that change. Annoying, but probably a good thing. Makes it difficult to explain to managers who insist on this feature, though. – GregL Apr 04 '17 at 07:57
  • that's what I'm going through now. marketing wants to change it... they want both the text and the look and behaviour, neither of which are possible anymore. Just sucks that Google makes a statement to disallow it (for good reason) but then overrides it on their own sites. – gteh Apr 04 '17 at 08:05
  • @Kaiido I updated the question with a pic from firefox. So it seems it is possible, or google made arrangements with other browsers to allow their custom messages. – gteh Apr 04 '17 at 08:16
  • naah, I think they've got some hackish way to do so, I would be very surprised they kindly asked FF to introduce backdoors for this service. I can't access this site myself, so can't check the how though... Is this from any way of closing the page or only when clicking on a link ? (e.g does it work also when you reload, close tab etc. ?) – Kaiido Apr 04 '17 at 08:17
  • [From the docs](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload) - _Starting with **Firefox 4**, **Chrome 51**, **Opera 38** and **Safari 9.1**, a generic string **not under the control** of the webpage will be shown instead of the returned string_ – Alon Eitan Apr 04 '17 at 08:20
  • @Kaiido I found the code, or at least some of it, where the custom message is set, but it is part of a 6700 line minified JS file that is impossible for me to trace through – gteh Apr 04 '17 at 08:21
  • Could you post it on pastebin ? I don't promise I'll find it but I'm quite interested. – Kaiido Apr 04 '17 at 08:28
  • @Kaiido it happens when clicking the back button in the browser or attempting to close the tab – gteh Apr 04 '17 at 08:28
  • @Kaiido I tried adding it to pastebin, its 4mb of text I can't seem to paste it. try this https://drive.google.com/file/d/0B5YPlgqcvgUuLXFJVWdfQ25TUVE/view?usp=sharing – gteh Apr 04 '17 at 08:33
  • They use `confirm`, but how they do prevent/override onbeforeunload is still a mistery for me... – Kaiido Apr 04 '17 at 08:55

0 Answers0