-
-
Save oraricha/6380306 to your computer and use it in GitHub Desktop.
Invalidate session on tab or window close (not tested!!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*JS code begins here*/ | |
/*Global js variable to decide whether to call session invalidate function*/ | |
var validNavigation = false; | |
//Called when page loads initially | |
jQuery(document).ready(function() { | |
//Call to wireupEvents | |
wireUpEvents(); | |
}); | |
//Function called when the page loads | |
function wireUpEvents() { | |
window.onbeforeunload= function() { | |
if (!validNavigation) { | |
/*This JS function calls my managed bean method to invalidate session.*/ | |
windowCloseJsFunction(); | |
} | |
} | |
// Attach the event keypress to exclude the F5 refresh | |
jQuery(document).bind('keypress', function(e) { | |
if (e.keyCode == 116) { | |
alert('116'); | |
validNavigation = true; | |
} | |
}); | |
// Attach the event click for all links in the page | |
jQuery("a").bind("click", function() { | |
alert('click a'); | |
validNavigation = true; | |
}); | |
// Attach the event submit for all forms in the page | |
jQuery("form").bind("submit", function() { | |
alert('form'); | |
validNavigation = true; | |
}); | |
// Attach the event click for all inputs in the page | |
jQuery("input[type=submit]").bind("click", function() { | |
alert('input'); | |
validNavigation = true; | |
}); | |
//Attach button click for all inputs in the page | |
jQuery("input[type=button]").bind("click", function() { | |
validNavigation = true; | |
}); | |
} | |
/*JS code ends here*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment