如何从任何页面的JavaScript访问谷歌浏览器扩展 [英] How to access google chrome extension from any page's javascript
本文介绍了如何从任何页面的JavaScript访问谷歌浏览器扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚如何从普通网页调用我的扩展。
我发现的所有文档似乎都是用于扩展之间或内容脚本与扩展之间的通信。
任何指针都非常感谢!
解决方案
我认为您应该制作一个内容脚本,将一个对象注入到您的页面中,以调用您的扩展名。
创建一个内容脚本,将YourExt.js注入到每个页面中,其中应包含:
var YourExt = {
doThis:function(){
chrome.extension.sendRequest('doThis');
},
找时间做:函数(){
chrome.extension.sendRequest({
动作: '找时间做',
PARAMS:[ '富','条']
});
}
}
I am trying to figure out how can I call into my extension from a normal web page. All documentation that I find seems to be either for communication between extensions, or between content scripts and extensions.
Any pointers are much appreciated!
解决方案
I think you should make a content script, that injects an object into your page that calls your extension.
Create a content script that injects YourExt.js into every page, which should contain:
var YourExt = {
doThis: function () {
chrome.extension.sendRequest('doThis');
},
doThat: function () {
chrome.extension.sendRequest({
action: 'doThat',
params: ['foo','bar']
});
}
}
这篇关于如何从任何页面的JavaScript访问谷歌浏览器扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文