3

How do I insert an entry into browsing history so back button goes to different page 1st click then original page on 2nd click?

So if you need a good explanation of what I want done, go to: https://secure.exitjunction.com/howitworks.jsp

I just need a script that will allow me to insert an entry in the browsing history so when back button is hit, the user will be taken to my special page.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
Sky
  • 203
  • 4
  • 7

2 Answers2

3

Here is a link to a jQuery Plugin:

jQuery Plugin

IEnumerator
  • 2,960
  • 5
  • 31
  • 33
  • there are plenty of answers on google for this. I recommended an option that uses jquery but there are straight javascript options for this. – IEnumerator Apr 16 '09 at 00:20
  • This is the best plugin by far to work with history, and I've worked with a number of them including a couple of standalone libraries. Even YUI's history object has some bugs in it. This one is the best of them. – cgp Apr 16 '09 at 00:52
  • I should also note, even if you were to "write your own", I would use this one as the reference implementation. – cgp Apr 16 '09 at 00:52
  • again - use this to get an idea for the code since you are not interested in adding google analytics support – IEnumerator Apr 16 '09 at 00:59
  • Thanks NTulip and altCognito - this gives me a basis to work from. – Sky Apr 22 '09 at 17:34
1

You can't directly manipulate the browsing history.

Such a feature would be seen as a security hole (and it would be), so I doubt that any browsers would ever implement it.

You might be able to hack around it however by doing something like this:

NOTE: This entirely hinges around the assumption that the referrer will get changed by the back button. I don't think this actually happens, so it more than likely won't work, but hey.

You have two pages, PageA and PageB.

  • The user hits PageA
  • The page (on the client, using javascript) checks the HTTP referrer, and if it is not PageB, then it immediately redirects the user to PageB.
  • Now that you're on PageB, if the user clicks the back button, it will go back to PageA.
  • PageA will check the referrer, it willmay be PageB, so there is no redirect.
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328