动端浏览器取消右划后退 防止页面后退

網站架設,免費空間申請,架站技術交流區

ETERNAL
 
文章: 2937
註冊時間: 2003-12-03 11:08 pm
性別: 男生

动端浏览器取消右划后退 防止页面后退

文章ETERNAL » 2018-09-27 3:29 pm

$(function () {
//防止畫面下滑刷新
const target = window;
let lastY = 0;

target.addEventListener('touchmove', handleTouchMove);

function handleTouchMove(e) {
const { pageY } = e.changedTouches[0];
const scrollY = target.pageYOffset || target.scrollTop || 0;
if (pageY > lastY && scrollY === 0) {
e.preventDefault();
}
lastY = pageY;
}

//防止页面后退
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function () {
history.pushState(null, null, document.URL);
});
});


水色論壇 http://www.et99.net
簡恩峻分享

回到 架站討論

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客

cron