1

它花了很多天阅读数百种方法来帮助我做出我真正需要的东西。根本没有成功。

我需要的是这个:

1) 有一个按钮,该按钮仅在选项卡具有特定 url 时才有效。

2)点击它后,必须阅读页面的源代码,然后获取其中的一些片段以将它们发送到我的服务器页面,以便检查我的数据库的记录数(我假设使用 AJAX 和 javascript)。然后此页面应将其响应发送回扩展程序并填充弹出 html。

我知道看起来很容易,但如果不是扩展所需的代码,我需要工作流程。

非常感谢!

4

1 回答 1

0

好的,所以您可以检查选定的选项卡及其网址:

chrome.tabs.getSelected(null,function(tab) {
  workWithUrl(tab.url);
});
...
function workWithUrl(url){
  if (url == ...
     ...
}

为了能够检查这一点,您需要为“标签”添加权限

要处理页面源代码,请将其发送到 Web 服务并更改 popup.html:

var xhr = new XMLHttpRequest();
xhr.open("POST", "__server adress___", true);
//headers   
xhr.setRequestHeader("Content-Type", "application/json");

//response 
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {

    //response from service to popup.html
    document.body.innerHTML = xhr.responseText;
    }
}

//process page here 

xhr.send(pageText);

您还必须为服务器地址添加权限以显示,并且所有内容都应从 popup.js(或 html)执行。

于 2012-12-05T21:15:51.067 回答