문제

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

도움이 되었습니까?

해결책

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top