Question: ```
Page A
Page B
Page C

```

If the user is coming from `page A` do something on `page C` (within the same website)
If the user is coming from `page B` do something else on `page C` (within the same website)

What would be the best approach to do that in JS? (dont use `document.referrer`)

Answer: 
In my opinion, there are two decent solutions:

1. When Page A loads Page C, include a variable in the URL that essentially says "*loaded from page A*". (Same applies to Page B.)
2. When Page A is loaded, set either a cookie, `localStorage`, or `sessionStorage` variable that says "*loaded from page A*". (Same applies for Page B.) Then when Page C is loaded, check the variable to see if either Page A or Page B was the most recently opened page. (You may also want to set a timeout/expiration-time on the cookie, localStorage, or sessionStorage.)
What you can do is have a global variable that will hold the location. When you load a page. assign that variable the location

```
window.location.href 

```

or 

```
document.URL;

```

Another option would be using cookies.