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

469 Views Asked by At

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

2

There are 2 best solutions below

0
On

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.
  }
});
0
On

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