扫码关注官方订阅号
欢迎选择我的课程,让我们一起见证您的进步~~
有怎么问题吗
页面A
A.html
<a href="B.html">ABOUT</a>
js
var flag = sessionStorage.getItem('key');//取出B页面存的值 if (flag === '998') { console.log('页面是从B页返回的'); sessionStorage.removeItem('key')//返回到A页面时重置key的值 } else { console.log('页面是新进入的'); }
页面B
html
<button type="" onclick='back()'>返回上一页</button>
function back() { window.history.go(-1); } sessionStorage.setItem('key', '998');//在B页面存值
sessionStorage------有期保存
localStorage------无期保存
值必须为字符串(经测试可兼容到IE8,但IE不支持本地运行,需服务器端)
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
有怎么问题吗
页面A
A.html
js
页面B
html
js
sessionStorage------有期保存
localStorage------无期保存
值必须为字符串(经测试可兼容到IE8,但IE不支持本地运行,需服务器端)