If you add custom content in admin using ajax you probably want to trigger an alert when user wants to reload page or navigate on other page.
This is an event beforeunload bind to $(window)
If you use plain beforeunload you will have issues on WordPress because in edit post WordPress uses beforeunload.edit-post and when you press update or publish it will not unbind that event. To make it work use the code below.
Add this to your trigger in jQuery:
1 2 3 |
$(window).on( 'beforeunload.edit-post', function() { return true; }) |