Here's a sample from code that i wrote and seems to work ok (at least, last i tested it, i no longer work there), adapted for generics: http://pastie.org/1661648
So here's what i learned, now that my curiosity got roused... The beforeunload event will automatically generate the prompt. If you want to inject a custom message into that prompt (not speaking for FF4, as i haven't tested on that with my prior code), you assign that STRING to the event.returnValue property. i'm pretty sure that by assigning a value to event.returnValue, the prompt is fired. If it has no value by the time the handler returns, the prompt does not occur. The user is prompted with the built-in prompt, plus your custom message. The event will automatically cancel ITSELF if the user hits the Cancel button of the confirmation message. There's no need to put a confirm in the event handler yourself. That's what would cause the double-prompt, and the confirm you generate is ignored by the event anyway. That's the best i can recall, anyway. i hope it helps. -joe t. On Mar 11, 9:29 am, Walter Lee Davis <wa...@wdstudio.com> wrote: > On Mar 11, 2011, at 7:41 AM, Bertilo Wennergren wrote: > > > > > > > > > > > Here's a limitation with "beforeunload" (in case someone hasn't > > heard): > > > More of less the only thing you can do with "beforeunload", is to ask > > the user if he or she really wants to leave the page. A dialog > > will appear, and the user can choose to abort the unloading and stay > > on the page. Normally you can add your own text to this dialog, > > informing > > why it might be wise not to leave the page. In Firefox 4 this is no > > longer > > possible! The dialog will have the following canned text that you > > cannot > > change (it might be in another language though): > > > "This page is asking you to confirm that you want to leave - data you > > have entered may not be saved." > > > That's what the dialog will say in Firefox 4. You can't change it, > > and you > > can't add anything to it. If the reason for using "beforeunload" > > does not > > have anything to do with entered data, or if you'd like to inform > > the user > > precisely what kind of data would be lost, or where on the page it > > is to be > > found, or why it's would be so bad to lose it, you're out of luck. > > > This is all by design. > > > -- > > Bertilo Wennergren > > berti...@gmail.comhttp://bertilow.com > > Thanks, this is very interesting. I just tested with the following bit > of code: > > document.observe('dom:loaded',function(){ > Event.observe(window,'beforeunload',function(evt){ > evt.stop(); > if (confirm('Are you sure you want to close the > window?')) return > true; > }); > }); > > In Safari, I got what I expected -- my confirm dialog blocking the > window close. But in Firefox 3.latest, I got two dialogs. First was my > confirm, but when I okayed that I got the second, which was more or > less exactly the same as what you describe for FF4. I commented out > the confirm line, and got only the one alert, but then in Safari I got > no warning at all. > > I wonder if there's any way besides browser sniffing to work around > this double-warning? > > Walter -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.