【发布时间】:2016-10-30 08:04:51
【问题描述】:
我有一个网站“http://localhost/sample”。我需要在扩展中调用一个函数来回显一个单词并获得响应。如何实现这样的代码,需要什么权限
【问题讨论】:
标签: google-chrome google-chrome-extension extension-methods google-chrome-app
我有一个网站“http://localhost/sample”。我需要在扩展中调用一个函数来回显一个单词并获得响应。如何实现这样的代码,需要什么权限
【问题讨论】:
标签: google-chrome google-chrome-extension extension-methods google-chrome-app
使用Ajax、Websocket、Nativemessaging(您需要nativeMessaging 权限)或任何其他通信方式在扩展程序和本地服务器之间交换数据
以下代码发送一个简单的http get请求并输出响应。
您可能还想使用Fetch API 代替 Ajax,这取决于您的需要。
manifest.json
{
...
"permissions": [
"http://localhost/sample"
]
...
}
background.js
var xhr = new XMLHttpRequest();
xhr.onload = function() {
console.log(xhr.responsetText);
};
xhr.open('GET', 'http://localhost/sample');
xhr.send();
【讨论】: