Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent the use of BACK and FORWARD button

Status
Not open for further replies.

Rodie

Programmer
Jun 27, 2004
132
FR
Hi all [tongue]

I have a PHP web page that is filled little by little.

The thing is that I don't want the user to be able to click the BACK or FORWARD buttons to go the previous or following page visited.

Does someone has an idea how I can prevent that ?
 
It's one of those things that can't be done with the current browsers.

If you were setting up a stand-alone browser on a computer in the foyer of your local museum (for example) then you could put the browser into kiosk mode (that forces the page to full screen with no window chrome).

I bet you aren't, though. Sorry [smile]

Jeff


[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
There is no way, using JavaScript, to categorically stop the user from navigating back and forth successfully in all modern browsers.

Much like trying to hide source or stop images from being stolen: give up while you're ahead!

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Ok, it's what I thought too ... snif
Thanks to all of you !
 
But ............ :)

Is there a way, for that web page, to remove all the menu bars, toolbars ... Sometimes you have advertisings popups that are small windows without any bars on the top.

Is it possible ?
Thanks :)
 
... and be aware that I can right-click (in the windows world) and go back... and I can use command-left bracket (and right bracket) in the Mac world (for Safari at least)...

Just to say that if your web application relies on the user being never using the back/forward buttons... then it is going to be tricky to get a robust solution. It may be better to find a method to gracefully fail -- the users will learn quickly :)

I would imagine that a simple pop-up (as suggested) would suit for most of the people most of the time. And that's probably not a bad target.

Jeff


[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Ok guys

Even if I cannot prevent everything, the solution "no bars" is fine for me. My boss will call you if he does not agree :)
Thanks again
 
Why would you want to? So they don't see old data? Instead of trying to disable the back button, you should disable the browser's cache. That way, when the user clicks the back button a new request will be made to the server and the latest data from your datasource can be displayed to the user.
Code:
<html>
<head>
  <meta http-equiv="Expires" CONTENT="0">
  <meta http-equiv="Cache-Control" CONTENT="no-cache">
  <meta http-equiv="Pragma" CONTENT="no-cache">
</head>

Adam
 
I want to disable BACK so they see old data ... it's the contrary lol.

Imagine, you chat with someone and here is the conversation history, that you see on the web page:
- Hi, what's up?
- I'm fine, what about you ?
- Not much ...


Now, you press one time BACK, you obtain:
- Hi, what's up?
- I'm fine, what about you ?


You press a second time BACK, you obtain:
- Hi, what's up?

You press a third time BACK, you obtain: ... nothing ...

And you know that the principle of the chat is to keep the history in a kind of textarea with horizontal scrollbar. I don't want the user to be able to remove the history. It's the same in Messenger, AIM ...

I'm gonna work on your piece of code now.
Thanks to you !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top