微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Chrome扩展程序回调?

如何解决Chrome扩展程序回调?

| 我正在开发我的第一个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.
});
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。