Session
how to kill session automatically when browser closed?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suresh MRank #171 · 14K reputationPosted Mar 27, 2016, 3:53 AM EDT
Vivek KumarRank #272 · 9.3K reputationPosted Mar 27, 2016, 9:50 AM EDT
Mohammed Zaid MerajRank #1,662 · 922 reputationPosted Mar 27, 2016, 8:07 PM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Mar 28, 2016, 4:10 AM EDT
Vivek KumarRank #272 · 9.3K reputationPosted Mar 28, 2016, 4:16 AM EDT
Rohit ManeRank #2,595 · 536 reputationPosted Mar 28, 2016, 6:18 AM EDT
1. First create a page LogOut.aspx and in
Page_Loadevent, write this code:2. Then add the following JavaScript code in your page or Master Page:
script type="text/javascript"> var clicked = false; function CheckBrowser() { if (clicked == false) { //Browser closed } else { //redirected clicked = false; } } function bodyUnload() { if (clicked == false)//browser is closed { var request = GetRequest(); request.open ("POST", "../LogOut.aspx", false); request.send(); } } function GetRequest() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } script>3. Add the following code in the
bodytag of master page:Finally the code in Master page like this:
"javascript" type="text/javascript"> // var clicked = false; function CheckBrowser() { if (clicked == false) { //Browser closed } else { //redirected clicked = false; } } function bodyUnload() { if (clicked == false)//browser is closed { var request = GetRequest(); request.open("POST", "../LogOut.aspx", false); request.send(); alert('This is close'); } } function GetRequest() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } script>aditya immadi144 reputationPosted Mar 28, 2016, 8:46 AM EDT