'Handle for close event of PowerPoint app in the add-in (JS)

I was looking for a way to handle the closing event of the PowerPoint when developing an Add-in.

The only ones that were a bit close was the fact that we can detect the visibility change of the add-in with

Office.addin.onVisibilityModeChanged((args) => {});

Is there anything else that it can be used to detect the closing of the PowerPoint app? I need to send data to the server or ask the user if he wants the changes to be saved.

Thank you



Solution 1:[1]

There are no other events. You can use the onVisibilityModeChanged handler for that:

Office.addin.onVisibilityModeChanged().then(function (args) {
  if (args.visibilityMode = "Taskpane") {
     // Code that runs whenever the task pane is made visible.
  } else if (args.visibilityMode === "Hidden") {
     // Show prompt to the user.
  }
});

Solution 2:[2]

I think you are using the right approach, and please notice that Office.BeforeDocumentCloseNotification interface is on preview now, please consider using it with caution in production environments

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eugene Astafiev
Solution 2 LuyiHan