下面是代码:http://pastebin.com/UxhJAdMb
我想将getlink.js(chrome内容脚本)变量“found”发送到popup.html中的文本框
我不明白有关消息传递的文档:http://code.google.com/chrome/extensions/messaging.html(javascript新手)
另外,如何修改此正则表达式以查找所有与wwww.stackoveflow或http://www.stackoverflow.com
相似的网站var reg = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/g
答案 0 :(得分:1)
Chrome浏览器一开始有点令人困惑,但您的听众却在错误的位置。您需要先从内容脚本发送请求,在您的情况下为getlink.js
# contentscript (getlink.js)
// ... code that does stuff here ...
chrome.extension.sendRequest({greeting: 'hello'}, function(response) {
console.log(response);
});
然后在popup.html中添加你的监听器:
# popup.html
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
// do something with request
// always send something back, even if it's empty
sendResponse({});
});