【问题标题】:Getting current window on a popup (Google Chrome extension)在弹出窗口中获取当前窗口(Google Chrome 扩展)
【发布时间】:2011-03-03 02:59:32
【问题描述】:

我正在构建一个 Google Chrome 扩展程序,并试图在弹出窗口中获取选定的窗口。 (我说的是当您单击扩展程序图标时显示的弹出窗口)。

我尝试使用文档,但我没有很好地理解它。具体来说,我尝试使用:

chrome.windows.getCurrent(function(w) {
    chrome.windows.get(w.id,
    function (response){
        alert(response.location.href);
    });
});

但它没有用。有什么想法吗?

谢谢 (如果英语不好,请见谅)。

【问题讨论】:

    标签: google-chrome-extension


    【解决方案1】:

    1) 您是否在清单中添加了“选项卡”权限?

    {
      "name": "My extension",
      ...
      "permissions": ["tabs"],
      ...
    }
    

    2) 如果您想知道当前窗口中选定选项卡的当前 URL,您应该使用 tabs API 而不是 windows API

    chrome.windows.getCurrent(function(w) {
        chrome.tabs.getSelected(w.id,
        function (response){
            alert(response.url);
        });
    });
    

    【讨论】:

      猜你喜欢
      • 2014-11-19
      • 2011-09-27
      • 2013-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-08
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多