简体   繁体   English

防止浏览器后退按钮不转到上一页

[英]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. 我尝试搜索许多文章,但找不到任何解决方案。

Try this 尝试这个

<script type="text/javascript">
        window.history.forward(1);
 </script>

Or you may read this 或者你可以读这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 防止转到浏览器后退按钮上的上一页 - Prevent going to the previous page on browser back button 我需要使用浏览器按钮返回上一个动态页面 - I need to use the browser button to go back to the previous dynamic page 单击浏览器的“后退”按钮时,返回上一页的上一个位置 - Go Back to the Previous Location on Previous Page when Clicking Browser Back Button 浏览器 go 回到上一页的活动div - Browser go back to active div in previous page 即使更改了哈希值,如何在网页中单击浏览器后退按钮时返回上一页? - How to go back to the previous page when browser back button is clicked in a webpage even when the hash is changed? 当按下浏览器后退按钮(在 Javascript 中)时,如何将特定变量传递给 go 返回上一页? - How to pass a specific variable to go back to the previous page when the browser back button is pressed (In Javascript)? 单击浏览器后退按钮时如何转到当前页面的上一页 - How to go previous page of current page , while clicking browser back button Cakephp 2,返回/取消按钮转到上一页 - Cakephp 2, back/cancel button to go to the previous page 防止返回上一页的按钮-angularjs - prevent back button on to previous page - angularjs 返回浏览器的后退按钮以显示先前的值 - go back with browser's back button showing previous value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM