我在我的chrome扩展的background.js中有以下函数来获取当前选项卡的url:
function getCurrentUrl() {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
var tab = tabs[0]
var keys = []
for(var key in tab) keys.push(key + '-' + tab[key])
alert(keys.join(', '))
})
}但是,警报对话框告诉我:
active-true, height-456, highlighted-true, id-301, incognito-false, index-6, pinned-false, selected-true, status-complete, width-717, windowId-262“tab”对象似乎没有url属性,就像上面的其他答案所建议的那样。我做错了什么?
发布于 2014-01-09 07:52:19
若要访问url,请向manifest.json添加以下内容:
“权限”:“选项卡”
来源:http://developer.chrome.com/extensions/tabs.html
https://stackoverflow.com/questions/21013247
复制相似问题