I couldn't find anything on the web: is there a function to search the window.history page stack? I'd like to find out if a user has already visited a page without using cookies or sessionStorage?
Asked
Active
Viewed 267 times
1
-
Does this answer your question? [Access my entire browsing history via Javascript](https://stackoverflow.com/questions/13369829/access-my-entire-browsing-history-via-javascript) – Heretic Monkey Oct 13 '20 at 12:32
-
Hm, kind of, thx, but is there a way of determining if the user has already visited a page? On an AJAXED page, I'd like to use window.scrollTo(0,0) if the page has not been visited yet. Preferably without using cookies or similar storage containers. – Anna Oct 13 '20 at 12:36
-
You'll want to actually read the answers to the linked questions in full to find out the answer. Which is no. – Heretic Monkey Oct 13 '20 at 12:39
-
@Anna You could use localStorage (you haven't excluded that one) or use a server-side tracking API where you would record the visit. – plalx Oct 13 '20 at 12:49
2 Answers
0
"For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history." - MDN

plalx
- 42,889
- 6
- 74
- 90
-
Which is not a reason to discredit a valid answer. I forgot to check for duplicates and vote to close now. – plalx Oct 13 '20 at 12:40
-
-
Why vote to close!? My follow up question is: On an AJAXED page, I'd like to use window.scrollTo(0,0) if the page has not been visited yet. Preferably without using cookies or similar storage containers. – Anna Oct 13 '20 at 12:44
-
@Anna Like I said ideally you'd have to use `localStorage`, `cookies` OR a server-side tracking mechanism (better control on tracking lifetime). The `:visited` idea of the other answer is also interesting as long as you hide the implementation details away. – plalx Oct 13 '20 at 13:49
-
-
-
The JS code executing on a web-page is non-privileged while JS code from an extension is priviledged. See [MDN ref](https://developer.mozilla.org/en-US/docs/Glossary/privileged_code). – plalx Dec 30 '22 at 16:13
0
You could try to make use of the css styling the :visited
selector for an a
tag. Put a hidden div on your page that contains an a
tag with its href set to the first page. Add a css style for it using visited selector and then check the styling of the a
tag to see if it matches that styling.

ATD
- 1,344
- 1
- 4
- 8
-
This is precisely why the browser makers stopped honoring the `:visited` pseudo selector; spammers and other malcontents tracking people's activity on the web. – Heretic Monkey Oct 13 '20 at 20:45
-
@HereticMonkey Indeed - that's one advantage of using old versions of browsers ;o) But, being serious, if I wanted to know if a user has visited one of my pages, I would do something on the page to register that fact and not try to hack into a user's private data to find out. I'm just putting this Question on the pile with "I **need** to see a user's local files/cookies/all localStorage/details of extensions they are using etc etc etc" However, I thought it was being kept for the same protocal/domain/port pages - like localStorage? – ATD Oct 14 '20 at 06:03