Closed Thread Icon

Topic awaiting preservation: Back Button Detection (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8924" title="Pages that link to Topic awaiting preservation: Back Button Detection (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Back Button Detection <span class="small">(Page 1 of 1)</span>\

 
Simon Figg
Nervous Wreck (II) Inmate

From: Dublin, Ireland
Insane since: Oct 2003

posted posted 10-27-2003 13:14

Can anyone tell me if it is possible to detect when a page is being displayed because the user pressed the back button rather than by following a link?

Thanks,
Simon



[This message has been edited by Simon Figg (edited 11-25-2003).]

rickindy
Nervous Wreck (II) Inmate

From: Indianapolis, In USA
Insane since: Jan 2002

posted posted 10-27-2003 13:48

An age-old problem. As far as I know, it's practically not possible.
You might be able to do some kind of detection using server-side scripting, but no way through javascript.
I'd love to be proven wrong on this.


Few problems in life can't be solved by chocolate

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 10-27-2003 14:18

You can check the window.history object. If window.history.current != window.history[ window.history.length -1 ], the chances are big that the users pressed the back button. But I'm not quite sure how to handle the users going back and forth in the history, nor how to handle if someone goes several times to the same page during the same session.

Hope that helps,

Mathieu "POÏ" HENRI

[This message has been edited by poi (edited 10-27-2003).]

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-27-2003 17:08

Interesting, is there any particular reason why you'd want to do this?

Maybe there's a different/better solution to your problem that doesn't require you to know how the user navigates your website as I can only think of one plausable situation that you would need to do soemthing like this (say, if you were using those nasty iframe buffering tricks with loading pages as place holders -- has a tendancy to reak havok an a browsers history list).

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-27-2003 17:10

The general answer to "I want to control the user's back button or history" is "find another way to accomplish what you're trying to do." Pretty much anything you try to do to manipulate the back button or the history won't work right in all cases.

Simon Figg
Nervous Wreck (II) Inmate

From: Dublin, Ireland
Insane since: Oct 2003

posted posted 10-27-2003 19:46

Thanks to poi, I'll try that solution tomorrow. In case there's another way, let me explain what I want to do. I have a button on a web page which when pressed displays a page called random.htm. This contains a bit of Javascript which then redirects the browser to a random web page within my site - this works perfectly. The problem occurs when the user presses the back button. The previous page in the history is random.htm, so what happens is that the user gets redirected to another random page. What I want is to be able to detect this situation so I can redirect the browser to the initial page with the random button on it - i.e. to behave as though the random.htm page was never displayed.

As I type this, it occurs to me that I might be able to manipulate the history object to remove random.htm, or even prevent it from being added in the first place. Can I do this from within the random.htm Javascript?

If you want to see the problem, go to www.iol.ie/~aftereffects and push the 'die' button at the bottom of the screen. Then try the backbutton.

Cheers,
Simon



[This message has been edited by Simon Figg (edited 11-25-2003).]

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 10-27-2003 20:09

Simon Figg: If you don't want to see the random.htm page parasiting your history, use the location.replace( ... ) function to redirect to the page selected at random in your site. This function crush current entry in the history. And voilà.

Mathieu "POÏ" HENRI

Simon Figg
Nervous Wreck (II) Inmate

From: Dublin, Ireland
Insane since: Oct 2003

posted posted 10-28-2003 10:11

Poi, that's perfect. Many Thanks!

« BackwardsOnwards »

Show Forum Drop Down Menu