[英]Prevent browser back button to not go to previous page
I want to prevent browser back button to not go to previous page. 我想防止浏览器后退按钮不转到上一页。
For this I tried below code: 为此,我尝试了以下代码:
<script type = "text/javascript" >
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };
</script>
but when I click on browser back button continuously 2-3 times at one go, it again redirects to previous page. 但是当我一次连续点击2-3次浏览器后退按钮时,它将再次重定向到上一页。 So my above code fails. 所以我上面的代码失败了。
I don't want user to go to previous page. 我不希望用户转到上一页。
I tried this code as well: 我也尝试了这段代码:
<script>
$(document).ready(function () {
function disableBack() { window.history.forward() }
window.onload = disableBack();
window.onpageshow = function (evt) { if (evt.persisted) disableBack() }
});
</script>
but this code is removing the scroller from browser and I am unable to scroll the page. 但是此代码正在从浏览器中删除滚动条,并且我无法滚动页面。
Please reply some solution. 请回复一些解决方案。 I tried searching many articles but could not find any solution. 我尝试搜索许多文章,但找不到任何解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.