想实现的功能是点击某个页面的后退按钮的时候调到一个特定的页面而不是上一页
直接操作歷史紀錄
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');
}
});