1

How would you access the users history using javascript as seen on other websites?

I am trying to access user history and view it to help me with search engine optimization. I want to see what users view before an after visiting my site. Is this possible or can it not be done just with javsascript? Any positive help would be appreciated. I know others have tried asking this question but no answer was helpful. I know there is a function that makes this possible called window.history!

Mudassir
  • 1,136
  • 1
  • 11
  • 29
  • 6
    I would truly hope this remains impossible, otherwise it's a hellish security breach. On which 'other websites' have you seen this? – David Thomas Apr 10 '14 at 14:39
  • possible duplicate of [Can we get browser history by using Javascript?](http://stackoverflow.com/questions/11556781/can-we-get-browser-history-by-using-javascript) – Cameron Brown Apr 10 '14 at 14:40
  • Just to give a straight answer: Nope, not possible. – Cerbrus Apr 10 '14 at 14:41
  • Answer: not at all. to put it bluntly, this information is none of your business! – collapsar Apr 10 '14 at 14:45
  • @DavidThomas Hello, I have seen this function on javasccript reference websites however I am not sure on how to use it. the function in window.history go(-2) which makes the user go back two pages – Mudassir Apr 10 '14 at 14:49
  • 1
    @IPADDRESS That only navigates to a prior page. That doesn't allow you to "access the users [sic] history" though. – FreeAsInBeer Apr 10 '14 at 14:50

3 Answers3

1

The only thing you can use is

document.referrer

Which will only return the URL of the previously visited page.

EDIT: I also might add that Google Analytics is generally used for this type of stuff, and will allow you to view what keywords are searched to get to your page.

Akurn
  • 392
  • 1
  • 5
  • It should be noted here that this `referrer` value should not be trusted 100% - just like the equivalent header value... – Lix Apr 10 '14 at 14:47
  • can you an example please – Mudassir Apr 10 '14 at 14:50
  • `document.referrer` will return the previous page URL as a string in Javascript. You could then log it to a database or something using Ajax. jQuery example: `$.post("logreferrer.php", {previousPage: document.referrer;});`. But Like I added, your better off using something like Google Analytics to get more in-depth search queries – Akurn Apr 10 '14 at 14:57
0

It's not possible to grab the history using JS. You can use window.history to navigate forwards/backwards in history (or push a different state to it) but you're not able to grab all the pages previously visited.

You can also use document.referrer to grab the website that linked to your site. This is used for analytics and such but cannot do what you're asking.

FreeAsInBeer
  • 12,937
  • 5
  • 50
  • 82
0

This is not possible using JS. If you're thinking about doing something like what the big websites (facebook, google, etc.) do to target ads to you, they are using tracking cookies and mining all sorts of data from what you do on their websites (some of which is pretty creepy).