Q:

Javascript history does not work

document.addEventListener('DOMContentLoaded', function () {
  displayRecentUrls("recentUrls");
});

function displayRecentUrls(divName) {
    var popup = document.getElementById(divName);
    var ul = document.createElement("ul");
    popup.appendChild(ul);
    var microsecondsPerWeek = 1000 * 60 * 60 * 24 * 7;
    var oneWeekAgo = (new Date).getTime() - microsecondsPerWeek;
    history.search({
      'text': '',              
      'startTime': oneWeekAgo  
    },
    function(historyItems) {
      for (var i = 0; i < historyItems.length; ++i) {
        var url = historyItems[i].url;
        var li = document.createElement("li");
        ul.appendChild(li);
        var a = document.createElement("a");
        a.href = url;
        a.appendChild(document.createTextNode(url));
        li.appendChild(a);
      }

    });
}

I wrote the code above to generate the browsing history for one week. It does not work. I'm new to Javascript so I may have made a silly mistake.

A:

As far as I know you cannot get browser history. What you can do however, is see if the user has visited certain URLs or not. Here's an example.
If you just want to go one page back, document.referrer gives you the page the user came from.

