Can we get browser history by using Javascript?

后端 未结 3 1624
死守一世寂寞
死守一世寂寞 2020-12-06 01:10

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.

相关标签:
3条回答
  • 2020-12-06 01:36

    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 
    
    0 讨论(0)
  • 2020-12-06 01:42

    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.

    0 讨论(0)
  • 2020-12-06 01:47

    If you are looking a way to navigate in browser history URLs. These links would be helpful.

    • http://www.w3schools.com/jsref/obj_history.asp
    • https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history/
    0 讨论(0)
提交回复
热议问题