扫码关注官方订阅号
想实现的功能是点击某个页面的后退按钮的时候调到一个特定的页面而不是上一页
业精于勤,荒于嬉;行成于思,毁于随。
直接操作歷史紀錄
window.history.back() // 上一頁
window.history.go(-2) // 前第二頁
監聽事件
jQuery(document).ready(function($) { if (window.history && window.history.pushState) { $(window).on('popstate', function() { var hashLocation = location.hash; var hashSplit = hashLocation.split("#!/"); var hashName = hashSplit[1]; if (hashName !== '') { var hash = window.location.hash; if (hash === '') { alert('後退按鈕點擊'); } } }); window.history.pushState('forward', null, './#forward'); } });
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
业精于勤,荒于嬉;行成于思,毁于随。