My app provides some macros. Inside those macros, users can edit some content. This content will be saved as soon as they press a save button inside the macro.
To prevent users from losing their content, I am registering a beforeunload
handler that shows a warning when navigating away if there is unsaved content.
Unfortunately, when navigating away inside Confluence, it seems that the iframe is removed from the DOM without triggering a navigation event, which causes the beforeunload
handler not to be triggered. This happens in particular when switching to the page editor or when switching to another page.
I haven’t been able to found a good technical implementation to manually call the beforeunload
handler in the iframe. So the only solution that I can think of right now would be to use the AP
bridge and provide an unload handler function there. The nice thing would be that it could allow custom unload messages. A similar thing happens right now when navigating away while there is an unsubmitted page comment.