Execute function on template's closing


Is it possible in Meteor to execute code when the user closes his browser window, or when he puts in the background?


Take a look at the wonderful mizzao:user-status package. From the server API section of the docs:

The UserStatus.events object is an EventEmitter on which you can listen for connections logging in and out. Logging out includes closing the browser; reopening the browser will trigger a new login event.

when he puts in the background?

Visibility API

Thanks, will look into it.