Question

I need to execute logout() function if user closes or refreshes page. I am using Angular.js library, and i need to broadcast that user left even if he doesnt click the proper button for that.

Should i just go with onbeforeunload or is there something in Angular.js i overlooked ?

Edit : I would like to avoid adding another module/library

Was it helpful?

Solution

You can use websockets for that (nodejs example):

socket.on('disconnect', function(){
    // do server stuff here
});

You are not guaranteed to handle this from client side, because user can simply close browser. another way is to use ajax to notify server "hey i'm online" with interval of time. if server stops receiving notification, that means user went offline (websockets are better way)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top