0

For example the user came to the page from example.com/home.html to the page example.com/checkout.html. I wonder if there is a way to assign a history back to something like example.com/new_offers.html?

So, when clicking his browser back button, instead of going to home.html the user will be redirected to new_offers.html

I know it may sound awkward, but it's just the example and the thing I need this for is a bit different. Also, I need to do this using JavaScript only (nothing server-side).

UPD: I figured out that it'd be clearer to ask whether it's possible to bind a handler to browser back button like (jQuery):

$(browser.backButton).click(function(e){ ... })

pnuts
  • 58,317
  • 11
  • 87
  • 139
Lapple
  • 3,385
  • 20
  • 20

3 Answers3

1

Instead of going to the checkout page from the home page, you can go to new_offers, which checks a variable checked_out. If checked_out is false, then redirect the user to checkout passing along all the form information. If checked_out was true, then display the new_offers page. checked_out will be set to true at the checkout page.

In this way, if the user clicks back at the checkout page, the user will actually go to the new_offers page.

I don't like this design very much as it means that a user has to click back twice quickly to get to a previous website, but it does satisfy your goals.

In other words, your current design does this:

home --> checkout

Instead, do this:

home --> new_offers -- (redirect) --> checkout

So that new_offers redirects to checkout immediately unless it sees that the user has already checked out.

Olhovsky
  • 5,466
  • 3
  • 36
  • 47
  • Thank you for the comment, excuse me for a bit blurry example. Have edited the question to make it more clear. – Lapple Mar 03 '11 at 05:16
  • Only thing I would add to this answer is that you really should not be doing this. You should not be manually manipulating the back button. If the user clicks back, they should be taken to the page they were at previously. If you want another mechanism, you should put a "Back" button or link somewhere on your site that will take them where you want them to go. – Idris Mokhtarzada Mar 03 '11 at 05:19
  • @Idris Mokhtarzada that was just the thing I was explaining to the client. I will quote you if I fail to find a solution. – Lapple Mar 03 '11 at 05:26
  • @Idris, absolutely I agree and that's why I mentioned that "I don't like this design very much [...]". I'm glad that you said it here more explicitly. – Olhovsky Mar 03 '11 at 06:09
1

Since you've modified your question to be about jQuery, you can use this jQuery plugin to solve this issue:

http://tkyk.github.com/jquery-history-plugin/

Olhovsky
  • 5,466
  • 3
  • 36
  • 47
0

Give this a read.

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

Kyle
  • 21,978
  • 2
  • 60
  • 61