[javascript] How to execute an action before close metro app WinJS

I want to trigger a function before closing my metro app but I don't know where such as

app.onactivated = function (args){   //all the actions here will be executed on app's activation } 

I want something for deactivation or app's closure, what's the proper way to do this in WinJS

This question is related to javascript winjs

The answer is


If I am not mistaken, it will be onunload event.

"Occurs when the application is about to be unloaded." - MSDN