Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    kkp
    kkp is offline
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to disable back button on Chrome browser

    Hi.
    I am unable to disable back button on Chrome browser.

    The below code is working for IE8 and FF browsers.
    <code>
    window.location.hash="no-back-button";
    window.location.hash="Again-No-back-button";//again because google chrome don't insert first hash into history
    window.onhashchange=function(){window.location.hash="no-back-button";}
    </code>

    How do workout for Chrome Browser? please help me.

    Thanks in advance...

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,636
    Thanks
    6
    Thanked 1,003 Times in 976 Posts
    You cannot effectively disable the browser’s back button. For one, you are going to annoy the hell out of the users by messing with their browsing customs and on the other hand, people can just disable JavaScript and you have achieved nothing.

  • #3
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    It may be critical for those anchors actually to exist in your document. I got this to work in Chrome, IE and Fx.

    Opera supports the event but not when the back button is used, which makes sense.

    Code:
    <body>
    <a id='noback'></a>
    <a id='noback_again'></a>
    
    <script type='text/javascript'>
    
    window.location.hash = "noback";
    window.location.hash = "noback_again";
    window.onhashchange = function(){ window.location.hash="noback"; }
    
    </script>
    Make sure you let users know why this functionality has been added.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by VIPStephan View Post
    you are going to annoy the hell out of the users by messing with their browsing customs
    what he said... really.

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    kkp, we have to know what the purpose is of doing this. There may be better solution than disabling the back button.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 584 Times in 565 Posts
    whenever [<] doesn't work, the next thing i click is [x]
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,627
    Thanks
    0
    Thanked 648 Times in 638 Posts
    There is only one thing that you can disable using JavaScript and that is JavaScript. Everything else can be easily overridden by your visitor.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Tags for this Thread

    Posting Permissions

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