I'm trying to force the user to LogOut from the system before close the browser. below is the code i only able to come up with.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(window).bind('beforeunload', function () {
return 'Please LogOut';
});
</script>
I would like to do something like below. Display an confirm box and if the user press OK then make an ajax call.
I tried below code but even the confirm box is not showing up.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
$(window).bind('beforeunload', function () {
var x;
var r = confirm("Please LogOut");
if (r == true) {
x = "LogOut";
var url = "/User/logOut/";
$.ajax({
url: url,
data: { UserID: 1},
cache: false,
type: "POST",
success: function (data) {
},
error: function (reponse) {
alert("error : " + reponse);
}
});
}
else {
x = "Stay On Page!";
}
});
</script>