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 10 of 10
  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,930
    Thanks
    6
    Thanked 1,041 Times in 1,014 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,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    kkp, we have to know what the purpose is of doing this. There may be better solution than disabling the back button.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    whenever [<] doesn't work, the next thing i click is [x]
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 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.

  • #8
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    I was actually going to try using a variation of this some in JS and some in php header to tick off would be hackers that try to post script in my forms and not to even consider that a typo but to rather make them feel warm and cozy by sending them to a not so nice "loser" page lol


    yes the user side settings are a pain sometimes to get around, but if it gets some of them, its worth it lol.... the back issue is alittle more tricky with Chrome and FF than it is with IE..


    i would share the page but its got some 'choice' words on it lmao...
    Last edited by durangod; 08-04-2014 at 12:06 PM.

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,565 Times in 2,543 Posts
    Quote Originally Posted by rnd me View Post
    whenever [<] doesn't work, the next thing i click is [x]
    Me too!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #10
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    Quote Originally Posted by Philip M View Post
    Me too!

    Gosh i hope the hackers feel the same way buddy That would be awesome.


  •  

    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
    •