Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out where in browser history the user is

I know I access browser history using history object, specifically, I can use history.back();, history.forward(); and history.go(item-number) (or history.go(url)). What I am trying to determine where in the browser history the user currently is.

Firefox, for example, may support accessing individual url's from the history, but that's not what I'm after, because the history of 20 url's may contain repeated url's.

Note that I am not interested in a history within my project - but rather browser history within any user's session.

For example, a user opened the browser and went through 20 pages - so the history contains 20 objects. Then the user hit back button 4 times - and ended up on the 16th of the 20 pages (or rather 15th of the 0..19 pages). Is there any way to get this current offset (16 or 15) using JavaScript? If yes, then how?

like image 896
Aleks G Avatar asked Oct 15 '12 12:10

Aleks G


1 Answers

history.length

returns the length of the current history.

sadly there is no method to figure out where in it you are.

like image 162
GottZ Avatar answered Oct 31 '22 21:10

GottZ