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);
}
});
}
我写了上面的代码来生成一周的浏览历史。这没用。我是 Javascript 新手,所以我可能犯了一个愚蠢的错误。