开发者

javascript "window.history.forward(1);" not working

I'm trying to prevent the back button from working on one of my asp.net mvc pages. I've read a开发者_运维知识库 couple of places that if i put "window.history.forward(1);" in my page it will prevent the back button from working on a given page. This is what I did in my page:

<script type="text/javascript">
        $(document).ready(function () {
            window.history.forward(1);
        });
    </script>

It doesn't seem to be working. Am I using this incorrectly or is this approach wrong? thanks.


The way I've seen this trick used is to put history.forward() on every page before the page where you don't want the back button to work, then every time the user hits the back button it forwards them back to where they were. The common use is to prevent others from returning to a page (usually in a given, linear sequence) once they have progressed. This is sometimes used in the sign-in sequence for banking websites, for example.

As far as I know, there is no way to actually disable the back button. Sometimes people get around this by opening the page in a new window, which will not have a history of pages preceding it, and thus nothing to go back to. Others simply display a warning message before going back to inform a user that they may lose unsaved data, if that is the main concern.

That said, maybe this will help you: http://viralpatel.net/blogs/disable-back-button-browser-javascript/


maybe:...

<script type="text/javascript">
   function disableBackButton()
   {
     window.history.forward();
   }
   setTimeout("disableBackButton()", 0);
    $(document).ready(function () {
       disableBackButton();
    });
</script>


Use on the page in which you don't want back button to work.

window.history.forward(1);


This is working for me... Hope it helpful for you..

<script type="text/javascript">
    window.history.forward();
    function noBack(){ 
    window.history.forward();
     }
</script>   

 $(document).ready(function() {
            noBack();
}); 


You can use

history.go(index)
index =0 //for the current page.
index>0 //e.g 1,2 for forward navigation
index<0 //e.g -1,-2 for backward navigation

history.go(-2)


<SCRIPT type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
</SCRIPT>

And in html Body tag write the following code.

<body  onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload=" " > 

Try this, it worked for me.


Not sure if this is relevant but I found it and it might be worth a try:

<script type="text/javascript">
    function preventBack() {
        window.history.forward();
    }
    setTimeout("preventBack()", 0);
    window.onunload = function() {
        null
    };
</script>


       <script>
            function preventBack() {
                window.history.forward();
            }

            setTimeout("preventBack()", 0);

            window.onunload = function () {
                null
            };
        </script>


window.history.forward();
function noBack()
{ 
    window.history.forward();
}

function setit() {
    noBack();
}


   <script>
        function preventBack() {
            window.history.forward();
        }

        setTimeout("preventBack()", 0);

        window.onunload = function () {
            null
        };
    </script>

The code needs to be on the page infront as well as the page you require for it to work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜