0

I want to implement a "back button" which will takes the user to the previous page on clicking.
Then the page before that, then the page before that and so on.
So far I have done something like this..

<?php
      $url = Mage::app()->getRequest()->getServer('HTTP_REFERER');
      if ((strpos($url, Mage::app()->getStore()->getBaseUrl()) !== 0) && (strpos($url, Mage::app()->getStore()->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK, true)) !== 0)) {
      $url = Mage::app()->getStore()->getBaseUrl();
}
?>
<div class="link2Back"><a href="<?php echo $url; ?>">Back to ... </a></div>  

but it just going back to the one recent previous page only.
What are the other possible methods for this problem ?

0

have you tried using javascript?

<a href=”#” onClick=”Javascript:history.back();”>GO back</a>

The only problem with this, is that when a user enters your product page from let's say, goolge, the user will be redirected to google.

You can also take a look at this threat: https://stackoverflow.com/questions/5285031/back-to-previous-page-with-header-location-in-php

1

Your solution is based on the http referer. The referer will be set from the page your customer was visiting before. So if you are visiting page A -> B -> C, when you arrive on C, referer will be B. Then, if you click on your link, you are going to B, and your referer will be C. So you are stuc

I see two ways of doing that :

A stack in your user session

Each page that you are visiting is adding its URL on the stack of visited pages. This stack is saved in the core/session. And if the page you are visiting is the page on the top of the stack, then it means you went back, and you need to remove it. The URL to go back is the one on the top of the stack.

Using Javascript with history.back

You can also use the javascript method window.history.back(); that will make the user go back as if he used the back button of his browser.

0

This is the way to do it.

<button type="button" title="<?php echo $this->__('Continue Shopping') ?>" class="button btn-continue" ><a href="#" onClick="Javascript:history.back();" style="text-decoration: none;"><span><span><?php echo $this->__('Continue Shopping') ?></span></span></a></button>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.