当前位置:网站首页>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 .
边栏推荐
猜你喜欢

easyExcel设置行隐藏,解决setHidden(true)失效问题

Use Anaconda to configure the tensorflow of GPU Version (less than 30 series graphics cards)

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

DDD landing is called an advanced

Leetcode · daily question · 919. complete binary tree inserter · hierarchy traversal · BFS

Looking at the next step of BAIC bluevale through the 8billion fund-raising, product upgrading and building core capabilities are the key words

Opencv error: (parameter or structure field)) unrecognized or unsupported array type in functon 'cvgetmat‘
![[tensorflow & pytorch] image data enhancement API](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[tensorflow & pytorch] image data enhancement API

【TensorFlow&PyTorch】图像数据增强API

UE4 how to render statically? 5 steps to generate static rendering
随机推荐
2020 AF-RCNN: An anchor-free convolutional neural network for multi-categoriesagricultural pest det
HCIP第十四天
Leetcode-202. happy number
ELS message loop
Classic interview questions -- three characteristics of OOP language
Where can Lora and nb-iot be used
QT notes - Q_ Q and Q_ D learning
QT笔记——临时的悬浮窗口
What are the methods of array sorting in JS
NFT因无意义而美丽
LDP related knowledge points
Canvas -- drawing of rectangle -- making of histogram
tf.constant用法
C语言预处理指令以及Makefile脚本讲解
Opencv saves pictures in the specified format
【 Kotlin 中的类和对象实例】
Alibaba Sentinel - cluster traffic control
申请SSL证书,并给域名配置SSL证书,并部署服务器;SSL证书的下载和安装
Uncaught TypeError: $(...).onmouseenter is not a function js错误,解决办法:
了解预加载和懒加载、学会缓动动画