Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we get browser history by using Javascript?

Can we get browser history for my site with Javascript ?

I can see some of old posts and threads talking about that... but those approaches didn't work for me.

Is it possible or not and how?

like image 866
Mayron Avatar asked Jul 19 '12 08:07

Mayron


People also ask

How do I view JavaScript history?

history object allows you to access the history stack of the browser. To navigate to a URL in the history, you use the back() , forward() , and go() methods. The history. length returns the number of URLs in the history stack.

What is history in JS?

The JS history object contains an array of URLs visited by the user. By using history object, you can load previous, forward or any particular page using various methods. Property of JavaScript history object : length: It returns the length of the history URLs visited by user in that session.

What is JavaScript history back ()?

back() The History. back() method causes the browser to move back one page in the session history. It has the same effect as calling history.go(-1) .


2 Answers

You can make use of History object of javascript to do that

The history property has the return value as history object, which is an array of history items having details of the URL's visited from within that window. Also, note that the History object is a JavaScript object and not an HTML DOM object.

syntax of history property of Window Object:

window.history 
like image 105
Pranay Rana Avatar answered Oct 22 '22 14:10

Pranay Rana


For privacy reasons, no it is not possible to read clients browser history data.

If you are trying to observe or generate data about visitors for only on your domain, its possible to keep page information with sessions and cookies.

you can also collect click data on your websites clickable objects by your own scripts which are sending the data by ajax requests.

if you are running a one page application type website and generating your own url's with "pushState()" function, you just need to add some extra code to collect that data and send the information with ajax on page/url changes.

like image 23
Serdar Avatar answered Oct 22 '22 12:10

Serdar