This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

To Disable Back button in all the browsers

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently i'm using the following code to disable the back button in my jsp page, but it works fine only in IE.

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

Can anyone give the code to disable the back button in all browsers like opers, firefox, chrome etc..
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to heed http://faq.javaranch.com/java/InterfaceDesignersRule1.

Which brings up the question: why do you want to do this?
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf
The link is very usefull.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

whilst you cannot disable the browser back buttons, you can add onbeforeunload event which will allow you to add functionality before the page is left.

I used this to add a confirmation box to notify users that leaving the page would lose any unsaved changes.

Note though that you cannot attach this to just the back button, and whenever the user tries to leave the page via a link/forward/back/reload, they would get the message.

Sean
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guessing you have a typo in your code above since histroy is misspelled.

If you use proper headers and posts, you can expire a page when the back button is pressed.

Eric
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic