In my application I want user to take an single signin. when he is leaving the application. As name explains, It should happen only when user closes current browser tab or browser window or browser referesh button. Its possible using JavaScript OnUnload event. But the problem is that this event occurs on
I have handled first 3 cases but not able to detect browser Refresh and Back/Forward button click. Has anybody of you implemented such functionality, Please help me??
Thanks in advance!!!
A better way to know that the page is actually reloaded is user the navigator object that is supported by most of the new version browser. It uses the HTML 5 navigation time API.
//check for navigation time API support
if (window.performance) {
console.info("window.performance work's fine on this browser");
}
if (performance.navigation.type == 1) {
console.info( "This page is reloaded" );
} else {
console.info( "This page is not reloaded");
}
source : https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API
Answered By : Rahul Jain
</div>
Use ajax on events. use (async javascript request)
<script type="text/javascript">
$(window).bind('unload', function(){
$.ajax({
type: "get",
async: false,
url: "URL CONTROLLER/FUNCTION"
});
});
</script>