I have a custom web part placed on one of the application page in SharePoint. This page it seems already have a function which gets executed on windows beforeunload Javascript event.
My problem is that I too need to execute some client side code (to prompt user for any unsaved changes in my web part) on windows beforeunload event.
How can I achieve this? I mean let the default event be fired as well as call my function also?
Appreciate any help.
This should be possible by checking for an existing handler assigned to the
onbeforeunloadevent and, if one exists, saving a reference to it before replacing with your own handler.Your web part might emit the following script output to do this:
This should allow you to inject your own logic into the page and make your own determination as to what code executes when the page unloads.