I have created an MVC asp.net project I have to save date time while the browser is closed. I tried the solution given before. A sample project would help me to understand how it works?
2 Answers
This way i implement. Use onbeforeunload event when tab is closing.
<script type="text/javascript">
window.onbeforeunload = function () {
window.location.href = '/logout'; //your action to logout
});
};
</script>
or ajax call to logout
<script type="text/javascript">
window.onbeforeunload = function () {
$.ajax({
type: "POST",
url: "/logout",
success: function (result) {
//
}
});
};
</script>
4 Comments
devhtml
I tried to call log out but the method is not invoked while closing the browser
devhtml
I tried it to call ajax post and it worked @Hien Nguyen Thanks for the reply
devhtml
while loading other page its logout how can i handle it?
Hien Nguyen
if current url and new current url are different, it will be load new page, you can check it in your controller