0

Apologies if my question sounds like a newbie question...but I could not find an appropriate answer.

I am trying to create 2 back buttons on my website that would bring the visitor back : 1. to the very first page he visited on my website 2. to the previous site (not page) he visited - so the site that brought him to my site basically.

Is this feasible by any chance ? And if so, can you please share your insights on the way to do it ?

Many thanks in advance for any help !

Peter B
  • 3
  • 2
  • yes it is feasible – brk Nov 03 '18 at 15:25
  • I'd suggest using session to store both of them. You want to look at `$_SERVER["HTTP_REFERER"]` and `$_SERVER['PHP_SELF']` – HTMHell Nov 03 '18 at 15:28
  • You van read this post [http referee](https://stackoverflow.com/questions/12369615/serverhttp-referer-missing) and [PHP manual] (http://php.net/manual/en/reserved.variables.server.php) – Ferdinando Nov 03 '18 at 16:16

2 Answers2

0

Maybe you can do something like this:

$(document).ready(function() {
   var sessionIsNew = sessionStorage.getItem('sessionIsNew');

   if (sessionIsNew == null) {
      sessionStorage.setItem('sessionIsNew', 'false');
      sessionStorage.setItem('entryUrl', window.location.href);
   }

}

// On click to your back button:
function backToEnrtryPage () {
    entryUrl  = sessionStorage.getItem('entryUrl');

    if (entryUrl != null) {
       window.location.href = entryUrl;
    }
}

More information about session in JavaScript

https://developer.mozilla.org/de/docs/Web/API/Window/sessionStorage

0

You can do it by manupulating the browser history, so to move once backward through history, just do:

window.history.back();

to back to initial entry page you can do somting like

var numberOfEntries = window.history.length;
window.history.go(- numberOfEntries );

the full api documentation from mozilla : https://developer.mozilla.org/en-US/docs/Web/API/History_API

eyetags
  • 159
  • 1
  • 4