UC浏览器js后退拦击不生效怎么办?解决方案!

关于浏览器的后退拦截在上一篇文章中已经有了详细代码,但最近在实际应用中却发现该在UC浏览器中并不能正常生效。那么该如何解决在UC浏览器上后退拦截不生效的操作呢?

其实也就是在源代码的基础上将延迟的时间加长,也就是把0改成800或者比这更大的数字。

如果你要问我什么原因,我也只能很抱歉的说:我也不知道,关于UC浏览器的机制只能说很憋屈。

完整代码:

<script language="javascript">
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/stealingyourhistory");
history.pushState(null, document.title, location.pathname);
window.addEventListener("popstate", function() {
if(location.hash === "#!/stealingyourhistory") {
history.replaceState(null, document.title, location.pathname);
setTimeout(function(){
window.location.href="biyan/2_1.html"
},800);
}
}, false); }(window, location));
</script>

代码已经经过测试,在UC中可以正常使用!如果不对之处,欢迎指出!

六月初字帖坊小程序 你想要的字帖模板及工具,这里都有!