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.)
Your description doesnt make a lot of sense (to me), especially because you havent included any framework/stack you're using (which this responsibility would likely fall on).

That said, I would use a variable with session getters and setters. You can parse the query string or URL, set that equal to a session variable, then get that session variable when you're ready to use it. 

Here's [how to use](https://stackoverflow.com/questions/18076013/setting-session-variable-using-javascript?answertab=active#tab-top) session getters and setters in javascript