做網(wǎng)站經(jīng)常不希望用戶(hù)用物理返回鍵章鲤, 因?yàn)槲锢矸祷鼗厝ゲ粫?huì)刷新晨横,可能會(huì)造成某種BUG脉漏,記錄一個(gè)設(shè)置物理返回去其他頁(yè)面的方法:
參數(shù)是 其他頁(yè)面的路徑
function notback(str){
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 === '') {
location.href=str;
}
}
});
window.history.pushState('forward', null, './#forward');
}
}