在弹出窗口中获取当前窗口(谷歌浏览器扩展) [英] Getting current window on a popup (google chrome extension)

查看:692
本文介绍了在弹出窗口中获取当前窗口(谷歌浏览器扩展)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Google Chrome扩展程序,并试图在弹出窗口中显示所选窗口。 (我说的是弹出窗口,当你点击extesion图标时显示)。

i'm building a google chrome extension, and i'm trying to get the selected window in a popup. (i'm talking about the popup that shows when you click in the extesion icon).

我尝试使用文档,但是我没有很好地理解它。
我尝试过使用:

I try to use the documentation, but i didn't get it well. I tryied to use:

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

但没有奏效。
任何想法?

But didn't work. Any ideas?

感谢
(对不起,如果英文不好)

Thanks (sorry if the english is bad).

推荐答案

1)您是否已将tabs权限添加到清单中?

1) have you added the "tabs" permission to the manifest?

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

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

2) It also looks like you should be using the tabs API and not the windows API if you want to know the current URL of the selected tab in the current Window

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

这篇关于在弹出窗口中获取当前窗口(谷歌浏览器扩展)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆