dcsimg
www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: can we disable back button on the browser?

  1. #1
    Join Date
    Dec 2004
    Posts
    36

    Question can we disable back button on the browser?

    hai friends

    i have a simple doubt

    can we DISABLE the back button on the browse..

    or atleast notify that it is not valid to go back.


    advance thanks

    by for now

    austin
    Share on Google+

  2. #2
    Join Date
    Nov 2004
    Location
    Buckinghamshire, England
    Posts
    8
    Inserting the following code will prevent users going back to the previous page -
    Code:
    javascript:window.history.forward(1);
    In NS 7.1, Firefox 1.0 and IE 6, pressing the back button or selecting "back" from the right click menu will simply cause the present page to be redisplayed. History is not updated. I haven't tried it with earlier browsers.

    I do not believe that you can get JS to display an alert when users hover over the back button, so you may need to warn them when they come to your site that you have effectively disabled the back button.

    You haven't mentioned why you wish to disable the back button. If your site displays only virtual pages that are generated on the fly and displayed directly to the window, then you may also wish to disable the default actions of some of the function keys and Ctrl key short cuts (and this may not meet with the approval of some posters!)
    Share on Google+

  3. #3
    Join Date
    Jul 2004
    Posts
    986
    Originally posted by Rob Dixon
    Inserting the following code will prevent users going back to the previous page -
    Code:
    javascript:window.history.forward(1);
    In NS 7.1, Firefox 1.0 and IE 6, pressing the back button or selecting "back" from the right click menu will simply cause the present page to be redisplayed. History is not updated. I haven't tried it with earlier browsers.

    I do not believe that you can get JS to display an alert when users hover over the back button, so you may need to warn them when they come to your site that you have effectively disabled the back button.

    You haven't mentioned why you wish to disable the back button. If your site displays only virtual pages that are generated on the fly and displayed directly to the window, then you may also wish to disable the default actions of some of the function keys and Ctrl key short cuts (and this may not meet with the approval of some posters!)
    That doesn't work!!
    Share on Google+

  4. #4
    Join Date
    Nov 2004
    Location
    Buckinghamshire, England
    Posts
    8
    I did a copy and paste of the code so I don't know how the space between java and script crept in, but I apologise for not having spotted it.


    The code should be -

    Code:
    javascript:window.history.forward(1);
    This does work as I described in my earlier post.

    When the user clicks on the back button, the browser will return to the previous page where the above code will force the browser to go forward
    again to the page from which the back button was clicked, thus nullifying the back button. The user will believe that the back button has been disabled.

    The above code must be in the previous page and in all pages.
    Share on Google+

  5. #5
    Join Date
    Nov 2004
    Location
    Buckinghamshire, England
    Posts
    8
    It has happened again - I don't know how. The code below is correct on preview. I will submit it again

    Code:
    javascript:window.history.forward(1);
    Share on Google+

  6. #6
    Join Date
    Nov 2004
    Location
    Buckinghamshire, England
    Posts
    8
    This is an error in the forum software - the code was correct when I submitted the reply.

    There should not be a space between "java" and "script"
    Share on Google+

  7. #7
    Join Date
    Dec 2004
    Posts
    364
    Originally posted by Rob Dixon
    This is an error in the forum software - the code was correct when I submitted the reply.

    There should not be a space between "java" and "script"
    This is not an error, but it is reality (I assume the space is inserted for security reasons). Anyway, using your code (with or without a space) will not modify the browser's behaviour if the back button is clicked.

    Regards PJ
     
    Share on Google+

  8. #8
    Join Date
    Jul 2003
    Location
    Boston Area, Massachusetts
    Posts
    3,489
    Please inform us as to why exactly you are trying to do this. There has to be a better, more sensible way.
    Share on Google+

  9. #9
    Join Date
    Nov 2006
    Posts
    3

    Back button - IE and Firefox

    Reference to previous comments, I have used with two pages A and B (linked) the following between the HEAD tags of A. Operating the link to B and with IE the back button becomes a refresh button (perfect).

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

    However with Firefox this doesnt work. Any comments or alternative JS for Firefox?
    Share on Google+

  10. #10
    Join Date
    Oct 2005
    Location
    Phoenix
    Posts
    29
    Just wondering it there is a way to disable the text "Back" when you right-click, instead of just not letting it happen?

    Thanks!
    Share on Google+

  11. #11
    Join Date
    Sep 2004
    Posts
    294
    Could you not just have the webpage open in a new window of its own, then from that point on use document.location.replace() to insure that there will be no history to go back to?
    Share on Google+

  12. #12
    Join Date
    Oct 2005
    Location
    Phoenix
    Posts
    29
    I've attached a document. Is there anyway to disable the "Back" part of that menu?
    Share on Google+

  13. #13
    Join Date
    Sep 2004
    Posts
    294
    Not within a web browser. But if your document opens in a new window/tab then it will have no history, making the back button and the back menu disabled. For all your links from that point on, have them use document.location.replace() so the history isn't updated.
    Share on Google+

  14. #14
    Join Date
    Oct 2005
    Location
    Phoenix
    Posts
    29
    That's a great idea. I have a .js file. Is there a way to put that line of code in my file, but just not have the startup page read that line of code?
    Share on Google+

  15. #15
    Join Date
    Oct 2005
    Location
    Phoenix
    Posts
    29
    So there's not a way to just eliminate that whole menu? Because I would also like to eliminate the "View Source" feature. Any ideas?
    Share on Google+

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles