Unsaved annotations prompt before closing the document

I would like to prompt the user to confirm if they try to navigate away from the page displaying a document in WebViewer (or they try to close the browser, or refresh the page), but I only want to prompt them if they have any unsaved Annotations.

Does the WebViewer provide any functionality for prompting the user to save annotations before leaving the page?

If not, can I know the event in which I can show a prompt to the user.

Thanks

Hi Priya,

You can listen to the AnnotationChanged event and add an unload listener to the tab.
Here is an example:

const onAnnotationChanged = (annotations, action, { imported }) => {
  if (!imported){
    annotationManager.removeEventListener('annotationChanged', onAnnotationChanged);
    window.addEventListener('beforeunload', e => {
      const message = 'You have unsaved annotations. Are you sure you want to leave?';
      e.returnValue = message;
      e.preventDefault();
      return message;
    });
  }
}
annotationManager.addEventListener('annotationChanged', onAnnotationChanged);

Best Regards,
Ahmad Moaaz
Software Developer
Apryse

Hi,
I tried the above code sample but the beforeunload event is not triggered when I close the page or refresh the page.
Is there any other alternative for the same.
Thanks
Priya

Hi Priya,

BeforeUnload is a browser API and not a WebViewer API.
You can find the documentation for it here:

Best Regards,
Ahmad Moaaz
Software Developer
Apryse

Thankyou for your help!!