Asked 7 years ago
27 Jan 2017
Views 20489
yogi

yogi posted

How to get url history in Javascript?

How to get url history in Javascript?
Rasi

Rasi
answered Nov 30 '-1 00:00


console.log(window.history)


window.history have all function we need for the browser history


back()
back() function will redirect previous url of current web history

window.history.back();


forward()
forward() function will redirect next url of current web history

window.history.forward();


go()
go() function will refresh current url of current web history

window.history.go();// refresh the current page


go(1) function will redirect next url of current web history

window.history.go(1);//go to next web page in history 

go(1) is equal to forward()

go(-1) function will redirect previous url of current web history

window.history.go(-1);//go to previous web page in history 

go(-1) is equal to back()


go(-2) function will redirect previous of previous url of current web history

window.history.go(-2);//go to previous of pervious web page in history 

go(-1) is equal to two time back()

go(n) , n would be positive or negative value which indicate go forward and backward in history and how many time
shyam

shyam
answered Nov 30 '-1 00:00

if you dealing with chrome Extension than
chrome.history object will help you get history of chrome browser


 chrome.history.search({
      'text': '',              // Return every history item....
      'startTime': oneWeekAgo  // that was accessed less than one week ago.
    } )



 chrome.history.search({
      'text': '',              // Return every history item....
      'startTime': oneWeekAgo  // that was accessed less than one week ago.
    },function(historyItems) {
      // For each history item, get details on all visits.
      for (var i = 0; i < historyItems.length; ++i) {
              var url = historyItems.url;
              alert(url);
      }
  });


if you dealing with firefox Extension than
[i]browser.history.search
give history result

var searching = browser.history.search({
  text: "",
  startTime: 0,
  maxResults: 1
});





searching.then(listVisits);
function listVisits(historyItems) {
  if (historyItems.length) {
    console.log("URL " + historyItems[0].url);
    
  }
}





Phpworker

Phpworker
answered Nov 30 '-1 00:00

use some of the open source work for browser history related manipulation

history.js

simple-history


Post Answer