当前位置:网站首页>Three solutions: when clicking the user to exit the login, press the back button of the browser, and you can still see the previous login page.
Three solutions: when clicking the user to exit the login, press the back button of the browser, and you can still see the previous login page.
2022-07-26 03:32:00 【The breeze also misses the rain】
On this question , I've tried many ways . My project is springboot + theamleaf Accomplished , At that time, my shutdown function was through a Tag for backend request , Back end cleanup session, Return to login page . Logically speaking , There's nothing wrong with it , however , By chance , After logging out , Click the browser's back button , You can still go back to the landing page , Because I use Ajax Front end interaction , therefore , The page does not need to be refreshed , You can still request data from the backend . that , Here's the problem , The solution I tried and The last best solution .
1. Disable the browser's back button , The code is as follows :
<script>
history.go(1);
var counter =0;
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
window.location='login';
// self.location="orderinfo.html";// If you need to jump to the page, use it
});
}
window.history.pushState('#',null,'#');// stay IE There must be these two lines in the
window.history.forward(1);
</script>I tried this method first , I found that I retreated quickly many times , It will fail , And it will affect the address in the address bar . Different browsers may have other problems .
2. It's said that it's because of the cache of the browser , Then disable page caching , The code is as follows :
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0">This is a HTML, Need to know , Compatibility processing is troublesome ,chrome Browser not yet supported , And other browsers occasionally fail . And just clearing the cache is useless , It is helpful for some problems , For example, after data execution .
PS: Clear cache in browser , It's used in conjunction with other sentences , You can go back to the page you visited before ,ie The browser must download the latest content from the server , Achieve the effect of refreshing .
3. Since it is the browser cache , Then add the version number , adopt js Add version number to the implementation file , The code is as follows :
<script type="text/javascript">
document.write("<script src='**.js?" + Math.random() + "'><\/script>");
</script>Since it's the browser cache trick , It's useless not to refresh , Therefore, this method will not work .( Whether it's browser caching or browser backtracking , They are innocent , These are all anti gentlemen , Don't guard against villains .)
4. Final solution ,Ajax Empty to background session, If it works , Then refresh this page , The code is as follows :
$('#user-exit').click(function () {
$.ajax({
url: "/loginOut",
type: "POST",
success: function (data) {
location.reload();
},
error: function () {
alert("Ajax Request error !");
}
})
})Session It runs on the server side ,JavaScript It runs on the client ,JavaScript You can't run server-side code directly . Not used Ajax, It can be used js, First the Session The value of is passed to an element in the front end , And then use js Access the value of the element .
边栏推荐
- Illustration leetcode - 5. Longest palindrome substring (difficulty: medium)
- Navicat连接云端服务器上的MySQL数据库
- Mbr3045ct Schottky diode, mbr0100, mbr2060ct diode parameters
- 【数学建模-规划模型总结】| MATLAB求解
- ELS message loop
- 【TensorFlow&PyTorch】图像数据增强API
- 了解预加载和懒加载、学会缓动动画
- 离线数据仓库从0到1-阶段二软件安装
- "Xiao Deng's view" the value brought by Siem to enterprises (II)
- Hcip day 8 notes sorting (OSPF routing control, Appendix E, anti ring, shortest path calculation, republication))
猜你喜欢

赶紧进来!!!用c语言基础知识几十行代码写一个猜数字小游戏

【 Kotlin 中的类和对象实例】
![[Yuri crack man] brings you easy understanding - deep copy and shallow copy](/img/26/b7330c7f5fdac55c8f5e9fa24658ee.png)
[Yuri crack man] brings you easy understanding - deep copy and shallow copy

Navicat连接云端服务器上的MySQL数据库

爆肝出了4W字的Redis面试教程

ext4、ntfs、xfs、btrfs、zfs、f2fs和reiserFS性能对比

QT笔记——临时的悬浮窗口

Derivation of linear regression principle

Small test (I)

Hcip day 8 notes sorting (OSPF routing control, Appendix E, anti ring, shortest path calculation, republication))
随机推荐
How to choose sentinel vs hystrix?
Canvas -- drawing of rectangle -- making of histogram
Unknown-Aware Object Detection:Learning What You Don’t Know from Videos in the Wild(CVPR 2022)
[experience sharing] strong recommendation - screenshot gadget FastStone capture (FSC)
[stl] priority queue priority_ queue
Easyexcel sets row hiding to solve the problem of sethidden (true) invalidation
Mbr3045ct Schottky diode, mbr0100, mbr2060ct diode parameters
A 4W word redis interview tutorial
Hcip day 8 notes sorting (OSPF routing control, Appendix E, anti ring, shortest path calculation, republication))
78. 子集
ByteDance (Tiktok) software test monthly salary 23K post, technical two-sided interview questions are newly released
赶紧进来!!!用c语言基础知识几十行代码写一个猜数字小游戏
QT notes - Q_ Q and Q_ D learning
els 修改光标、修改图标
Alibaba Sentinel - 集群流量控制
Classic interview questions -- three characteristics of OOP language
ue4如何进行静态渲染?5个步骤生成静态渲染
easyExcel设置行隐藏,解决setHidden(true)失效问题
Canvas - drawing pictures - dynamic drawing production
canvas——心电图的设计,以及如何清理画布