Home >Web Front-end >JS Tutorial >How to delete session in javascript
Javascript method to delete session: [setTimeout(function() { sessionStorage.clear(); window.parent.location.reload();var index =...].
The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
javascript closes the current page and clears the session.
Page:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>js关闭当前页清除session</title> </head> <body> <script language="javascript"> function save() { //存储session window.sessionStorage.setItem("this_session", "This is session!"); window.sessionStorage.setItem("user", "This is User"); //取出session var thisSession = window.sessionStorage.getItem("this_session"); alert(thisSession); } //执行sava() save(); // 这个脚本是 ie6和ie7 通用的脚本 //关闭当前页 function custom_close() { if(confirm("您确定要关闭本页吗?")) { window.opener = null; window.open('', '_self'); window.close(); //清除session sessionStorage.clear(); } else {} } function clearUser() { // sessionStorage.removeItem("user"); } //关于session </script> <input id="btnClose" type="button" value="关闭本页" onClick="custom_close()" /> <br/><br/><br/><br/> <input id="btnClose" type="button" value="清除User信息" onClick="clearUser()" /> </body> </html>
layui
//设定时间一秒后触发 setTimeout(function() { sessionStorage.clear(); window.parent.location.reload();//刷新父页面 var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); //关闭当前页 }, 1000);
Recommended learning: javascript video tutorial
The above is the detailed content of How to delete session in javascript. For more information, please follow other related articles on the PHP Chinese website!