本文介绍了如何清除浏览器关闭的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨 我在登录时创建网站,登录后我存储用户名&会话值中的密码,登录后我直接关闭浏览器,当我打开该页面时,它无需登录即可打开。 我想清除浏览器或标签关闭的会话。我正在使用下面的脚本,但它不起作用。 < script type = text / javascript > var clicked = 假; var xmlHttp var browser = 导航 .appName; function CheckBrowser(){ if (单击== false ){ xmlHttp = GetXmlHttpObject(); xmlHttp.open( GET, Default.aspx, true ); xmlHttp.onreadystatechange = function (){ if (xmlHttp.readyState = = 4 ){ // alert( xmlhttp.responseText) } } xmlHttp.send( null ) if (browser == Netscape){ window 。 location = ... / Default.aspx; alert( 浏览器已终止); openInNewWindow(); } } 其他 { // alert(Redirected); clicked = false ; } } function GetXmlHttpObject(){ var xmlHttp = null ; 尝试 { // Firefox,Opera 8.0 +,Safari xmlHttp = new XMLHttpRequest(); } catch (e){ // Internet Explorer 尝试 { xmlHttp = 新 ActiveXObject( Msxml2.XMLHTTP); } catch (e){ xmlHttp = new ActiveXObject ( Microsoft.XMLHTTP); } } return xmlHttp; } function openInNewWindow(){ // 将_blank更改为newWindow以加载同一新窗口中的所有链接 var newWindow = window .open( 。 ../ Default.aspx的); newWindow.focus(); return false ; } < / script > < body onclick = clicked = true; onunload = CheckBrowser() > 解决方案 http://dotnetbrilliance.wordpress.com/2012/06/03/如何清除所有会话值 - 当关闭浏览器在asp-net-4-0 / [ ^ ] 删除重复的链接 查看以下链接。 amnk.info提供的链接 [ ^ ]也很有用。 当用户关闭窗口时结束会话 [ ^ ] 它以非常简洁的方式描述每个方面。您将完全了解 Session.Abandon()以及在浏览器关闭时会发生什么以及如何执行此操作。 查找类似于CP 想清除关闭标签上的会话变量 [ ^ ] 如何在浏览器关闭时结束用户会话 [ ^ ] HiI am creating website in that login is there, after login i stores username & password in session values, after login i close browser directly when i open that page its open without login.I want to clear session on browser or tab close. I am using below script for that but its not working. <script type ="text/javascript" > var clicked = false; var xmlHttp var browser = navigator.appName; function CheckBrowser() { if (clicked == false) { xmlHttp = GetXmlHttpObject(); xmlHttp.open("GET", "Default.aspx", true); xmlHttp.onreadystatechange = function () { if (xmlHttp.readyState == 4) { // alert(xmlhttp.responseText) } } xmlHttp.send(null) if (browser == "Netscape") { window.location = ".../Default.aspx"; alert("Browser Terminated"); openInNewWindow(); } } else { //alert("Redirected"); clicked = false; } } function GetXmlHttpObject() { var xmlHttp = null; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function openInNewWindow() { // Change "_blank" to something like "newWindow" to load all links in the same new window var newWindow = window.open(".../Default.aspx"); newWindow.focus(); return false; } </script><body onclick="clicked=true;" onunload="CheckBrowser()"> 解决方案 http://dotnetbrilliance.wordpress.com/2012/06/03/how-to-clear-all-the-session-values-when-close-browser-in-asp-net-4-0/[^][EDIT] Duplicate link removedHave a look at the below link.The link provided by amnk.info[^] is also usefull.Ending Session when user close window[^]It describes each and every aspect in very concise way. You will get complete idea regarding Session.Abandon() and what happens and how to do this on browser close.Find similar at CPwant to clear session variables on closed tab[^]How to end user session when browser closed[^] 这篇关于如何清除浏览器关闭的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 20:56