1

我有一个好主意,它围绕用户所在服务器的 ips 展开。

我对制作 google chrome 扩展非常陌生,但我擅长构建一个 .

问题:我可以从用户所在的服务器获取 IP 吗?如果是这样,你会怎么做?

我在想只是 AJAX 将 url 发送到我自己的服务器,然后 ping 服务器将获取 ip 并将其返回/存储在某个地方。

4

1 回答 1

-2

您可以使用chrome.tabs API获取当前tab\web Page正在浏览的用户的当前 URL

示范

chrome.tabs.query({
    "currentWindow": true, //Filters tabs in current window
    "status": "complete", //The Page is completely loaded
    "active": true // The tab or web page is browsed at this state,
    "windowType": "normal" // Filters normal web pages, eliminates g-talk notifications etc
}, function (tabs) { //It returns an array
    for (tab in tabs) {
        _url_i_need = tabs[tab].url;
        //Do AJAX Stuff here 
    }
});

确保您tabs在清单中声明权限,如此处所示

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

参考

于 2013-01-17T14:14:39.410 回答