?
Solved

Disable back function in HTML

Posted on 2007-10-01
19
Medium Priority
?
1,358 Views
Last Modified: 2008-01-09
function cancelBack()
  {
  alert(event.keyCode);
    if (event.keyCode == 8 && event.srcElement.form == null)
    {
      event.cancelBubble = true;
      event.returnValue = false;
    }
  }

<body onkeydown = "cancelBack();">

I am using the javascript.
I use the above code do disable the back function in IE, but the problem is that when I disable the backspace key, I could not delete any words I enter in the text input.
How to I disable the back function and at the same time be able use the backspace to delete my input?
0
Comment
Question by:xiaoxin85
  • 6
  • 5
  • 4
  • +2
19 Comments
 
LVL 14

Expert Comment

by:Jai S
ID: 19989823
you probably cant disable the BACK button...but you can clear the HISTORY so that the back button is disabled by itself...
0
 

Author Comment

by:xiaoxin85
ID: 19989831
How do I clear it? It would be great if u can provide mi with the code thankx
0
 
LVL 10

Accepted Solution

by:
digitalZo earned 450 total points
ID: 19989839
Try this:
<a href="http://link" onclick="javascript:location.replace(this.href); event.returnValue=false;">Name of the link</a>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:xiaoxin85
ID: 19989843
digitalZo, sorrie mi dun get ur coding, wat is it for??? y use <a href> link????
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 19989853
That's the link you don't want the back button to work for. You can do it that way too.
0
 
LVL 14

Assisted Solution

by:Jai S
Jai S earned 450 total points
ID: 19989854
you can use this to clear history
javascript:history.clear();
0
 

Author Comment

by:xiaoxin85
ID: 19989875
jaiganeshsrinivasan:
I put ur code in my html, it still cannot work, it still go back to the previous page...
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 19989884
What CodeBehind language are you using? VB or C#? You can write a code in codebehind in the page that you dont want the user to return to. Will that do?
0
 

Author Comment

by:xiaoxin85
ID: 19989892
mi is using javascript to code. It is ok to write codebehind the page, javascript or vb also can
0
 
LVL 14

Expert Comment

by:Jai S
ID: 19989898
call this in your onload even
<body onload="javascript:history.clear();"
0
 

Author Comment

by:xiaoxin85
ID: 19989906
jaiganeshsrinivasan:

sorrie it still cannot....
0
 
LVL 10

Expert Comment

by:digitalZo
ID: 19989931
Try this on PageLoad in codebhind:

Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1D)
Response.Expires = -1500
Response.CacheControl = no-cache

0
 
LVL 10

Expert Comment

by:digitalZo
ID: 19989932
Response.Buffer = True
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1D)
Response.Expires = -1500
Response.CacheControl = "no-cache"
0
 
LVL 14

Expert Comment

by:Jai S
ID: 19989940
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 19990048
@digitalZo

You mean


<a href="page2.html"
onclick="location.replace(this.href); return false;">Name of the link</a>

on the previous page
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 450 total points
ID: 19990066
@jaiganeshsrinivasan: history.clear() is not a valid javascript function in the current browsers
0
 
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 150 total points
ID: 19990604
The back button is a function of the client software, not your server.  You cannot disable it without the ability to alter running conditions on the client machine, and that's a rare scenario at best.

Likewise, the history is a client data store.  You will not have access to alter it except to append a new URL as the user browses forward (or to replace the 'current' URL, as noted above).

Obviously, there are loopholes.  You can look here for one:

http://forums.asp.net/p/1132444/1806081.aspx

Your better option (I would say only option, but that's me) is to secure your application through your own code.  Depending on users to follow certain paths of behavior is never a good option.  Using a 'trick' to simulate coercion will only get you in to trouble as features or functionality are changed over time.  Failing to cache or forcibly expiring the cache does not prevent the page from being reloaded...it simply expires the version currently residing on the user's computer.

Within each page, a session variable should be set to indicate where the user is in the app.  Each page should also check that variable, and take action on any 'incorrect' values it finds.  For example, if the variable indicates the next step is 3, but the user is at step 1, print an error message and/or forward the user to the correct page.

Good luck!
0
 

Author Comment

by:xiaoxin85
ID: 19991059
Neither suggestion helps... Is ok... I solved myself.... Thankx guys for your suggestion...
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 19991145
Can you explain how you resolved the problem?  The information may help those that come after you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question