【问题标题】:Google Chrome: can't get current tab's url谷歌浏览器:无法获取当前标签的网址
【发布时间】:2014-01-09 06:39:20
【问题描述】:

我的 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

正如其他答案所建议的那样,“标签”对象似乎没有 url 属性。我做错了什么?

【问题讨论】:

    标签: javascript google-chrome url google-chrome-extension tabs


    【解决方案1】:

    要访问 url,请将以下内容添加到 manifest.json:

    “权限”:[ “标签” ]

    来源:http://developer.chrome.com/extensions/tabs.html

    【讨论】:

      猜你喜欢
      • 2013-08-05
      • 2013-05-14
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 2012-07-12
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多