[英]Executing script on a precise tab in Google Chrome extension
I want to execute a script on a precise tab of my browser.我想在浏览器的精确选项卡上执行脚本。 This script will give back a value.
此脚本将返回一个值。
I don't know what I have to use.我不知道我必须使用什么。 The Doc says that
contentScript
are called on every loading of a new page. Doc 说在每次加载新页面时都会调用
contentScript
。 I just want to execute the script once the user clicked on a button in my popup.html.我只想在用户单击 popup.html 中的按钮后执行脚本。
In your contentScript file add listener like this:在您的 contentScript 文件中添加这样的监听器:
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
//do job
sendResponse(...);
});
And in your popup.html
on click event:在你的
popup.html
点击事件中:
chrome.tabs.sendMessage(tabid, "message", function responseCallback(response) {
//...
});
more info http://developer.chrome.com/extensions/tabs.html#method-sendMessage更多信息http://developer.chrome.com/extensions/tabs.html#method-sendMessage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.