I am writing a JS which is used as a plugin. The JS has an onbeforeunload event.
I want suggestions so that my onbeforeunload event doesn’t override the existing onbeforeunload event (if any). Can I append my onbeforeunload to the existing one?
Thanks.
You only need to take care of this if you are not using event observing but attach your
onbeforeunloadhandler directly (which you should not). If so, use something like this to avoid overwriting of existing handlers.Unfortunately, you can’t prevent other (later) scripts to overwrite your handler. But again, this can be solved by adding an event listener instead: