0

have something like this: click in page A and redirect to page B, click in page page B redirect to page C, is there any way to get the URL of page A when I am in C page? and check if page A = 'domain.com/aboutus'.

I am not so good in javascript, I try to do this in PHP but is not work very well because the LastURL here is not the page that I want, maybe someone can show me an script example.

if (strpos(Mage::getSingleton('core/session')->getLastUrl(), 'checkout/cart') !== false) {
    Mage::getSingleton('core/session')->setIsFromCart('1');
} else {
    Mage::getSingleton('core/session')->setIsFromCart('0');
}
if (strpos(Mage::getSingleton('core/session')->getLastUrl(), 'onestepcheckout/index') !== false) {
        Mage::getSingleton('core/session')->setIsFromCheckout('1');
} else {
    Mage::getSingleton('core/session')->setIsFromCheckout('0');
}

Thank you

Robert
  • 812
  • 3
  • 18
  • 47

5 Answers5

1

use window location or href in javscript

  window.location="your URL";

or

  location.href=URL;

Ex.

  <script>
  window.location="http://www.tutorialspoint.com";
  </script>
Tosif
  • 36
  • 5
  • thank you Tosif, you have an example? how this can work? and how can check if page A = 'domain.com/aboutus' – Robert Mar 09 '16 at 06:19
0

You can use document.referrer but since you want to check url of page A when you are in page C, the best option will be to use a localStorage

brk
  • 48,835
  • 10
  • 56
  • 78
0

You can pass the page Url in querystring to C, like http://www.example.com/link/to/page/c?from=link/to/page/a, and then parse querystring to get the from address.

Ammar Hasan
  • 2,436
  • 16
  • 22
  • if you are redirecting from page a to b by using window.location.href = "http://www.example.com/link/to/page/b", then instead do it like window.location.href = "http://www.example.com/link/to/page/b?from=link/to/page/a". And then in page b, [parse the querystring][1] and forward the from to page c, using the same way of a to b redirection. [1]: http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – Ammar Hasan Mar 09 '16 at 06:49
0

You can store A page url in cookie like this document.cookie = window.location.href; and At page C you can get value form cookies

0

You can use this.

In page A

<script>
localStorage.setItem('pageA_url', window.location.href);
</script>

In page C

<script>
var pageA_url = localStorage.getItem('pageA_url');
</script>
Indrajit
  • 405
  • 4
  • 12