问题描述
|
我正在开发我的第一个Chrome扩展程序。我想我需要学习如何做回调。在使history.getVisits()有用时,遇到了麻烦。
我可以很好地检索HistoryItems,但是我不知道如何将VisitItems与HistoryItems结合使用。
chrome.history.getVisits({url:historyItemUrl},function(visitItems){
// I can loop through the visitItems,but...
// how can I access the historyItemUrl from in here?
// do I need to make a better function for the 2nd param?
});
我已经看过并尝试了SO中的许多回调示例,但是当我尝试使用自己的回调函数时,JS控制台一直在讲关于在getVisits()
中要求第二个参数的说法。我想我真的只是缺少回调的概念。
如果可以的话请帮助-谢谢!
解决方法
确保已将其添加到清单文件中:\“ permissions \”:[...,\“ history \”,...]
然后,您可以非常简单地访问historyItemUrl:
var historyItemUrl = \"http://stackoverflow.com/\";
chrome.history.getVisits({url:historyItemUrl},function(visitItems){
alert(historyItemUrl); // here you can access it.
});