views:

425

answers:

1

I have a strange issue from a client in that our code, which they include uses onbeforeunload() to trigger a dialog, but they are also including another companies code which also binds this event handler.

Is it possible for both to execute at the same time?

I've been reading this, http://oreilly.com/catalog/9780596101992 "JavaScript: The Definitive Guide, Fifth Edition" to try and help better understand what is happening in the browsers internals and the javascript stack, but it's proving quite mind bending.

I understand from reading the book that some events can be executed all at the same time if they are attached using the Level 2 API addEventListener() but the order will be up to the browser. However there is no mention of the onbeforeunload() event. Just the onunload().

Which leads me to the second part of the question. If an event is triggered in onbeforeunload() am I right in thinking that unless it returns true, the onunload() will never be called?

If anyone can shed some light on it, or hook me up with a nice tutorial/guide on either having multiple event handlers assigned to the same event, or specifically on these two events that would be ace.

Thanks

+2  A: 
T.J. Crowder
Fab answer, thanks! Seems I'll have to work around it. Or extend our onbeforeunload() wrapper to pass through values depending on conditions.
DavidYell
I'm having a similar problem with multiple unload listeners - only one gets fired...but only when I _don't_ have an alert call in one of the unload event handlers. Extremely weird. I'm thinking of posting a new question about it, unless there's perhaps a simple explanation that could go here?
Ash