Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Astatos2667yMaybe this helps a bit:
Since 25 May 2011, the HTML5 specification states that calls to window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event. See the HTML5 specification for more details.
Note also, that various browsers ignore the result of the event and do not ask the user for confirmation at all. The document will always be unloaded automatically. Firefox has a switch named dom.disable_beforeunload in about:config to enable this behaviour.
got it from mdn
if it doesnt help you, ill try to do my best as soon as i can Access a computer -
plusgut60377yDid you interact with the site before you close? Mozilla uses a prevention for unwanted popups. https://developer.mozilla.org/en-US...
-
Astatos2667yIn firefox, u can simply add an e.preventDefault ();
it will automatically asks you, if you want to leave the Page
unfortunately, this does not work in chrome...
maybe you could try to build your own popup, which appears on click on an external link, where the user has to choose, if He wants to leave or stay -
bbuck117ySpeaking from the user perspective you probably should not try to get this to work. I abhor this behavior anywhere I see it and prefer the standard "back button form state" the browser provides our something like Gmail's draft system. If there is incomplete work then do what you can too autosave it into local storage often enough so that when a user returns it'll be as if they never left. We need to move past this "no don't leave me" behavior and empower our users so that they feel free to behave however they want without being punished or questioned.
-
hawkes15727yIf I remember correctly, this was done to prevent pages from hijacking the user. A site could just ALWAYS preventDefault the event and stop the user from leaving.
You should be able to return a string in your onbeforeunload event handler that gets displayed to the user:
window.onbeforeunload = (ev) => {
return ev.returnValue = 'your message';
}; -
meister3437yGuys thank you very much for your comments.
@Astatos i just read it like after more than half of the day today. I thought my mod had a problem but turns out my firefox version was latest compared to my coworker. Then we traced some spec information from mozilla.
@plusgut just figured it out today too. After reading the firefox specification.
@bbuck we implemented our own back button that saves the information as a draft. For the browser back, it was simplier for to prompt the user if he/she wants to leave the page with unsaved information changes.
Lastly, i just also learned today that ios basically doesnt support onbeforeunload.
Again thank you every. Fairly new in webdev. Trying hard to catch up latest tech info is tough. I was doing softdev before so webdev is a bit of a challenge. -
plusgut60377y@meister you are welcome, I'm happy you figured it out.
And I always recommend the mozilla documentation, it really is that great. Especially the little quirks in the different versions are very interesting and described very detailed.
Damn. 3days and not yet finished with this bug.
Problem: in js, we want to popup a dialog to user that he us living the page.
So we used onbeforeunload.
Works well with chrome, ie and firefox (atfirst).
Then i updated my firefox to latest version and onbeforeunload is not triggering.
And it also occurs in tablet. Argh! Damn challenges on cross platform/browser compatibilities.
Help! Please
undefined
multibrowser
compatibility
beforeunload
crossplatform
javascript