Google browser plug-in development tutorial 3
background.js use
{ "name": "todo-plugin", "version": "0.9.0", "manifest_version": 2, "description": "chrome plugin demo", "browser_action": { "default_icon": "icon.png", "default_title": "Todo List" , " Default_popup " : " popup.html " }, " content_scripts " : [{ // page content to operate script " The matches " : [ " HTTP: // * / * " , " HTTPS: // * / * " ], // what conditions the implementation of the plug-in " JS " : [ " jquery.min.js " , " test.js " ] }], " background " : { "scripts":["jquery.min.js","background.js"] } }
background.js
function test(){ alert("test"); }
$ (function () { // first obtaining background page var BG = chrome.extension.getBackgroundPage (); // recall function in which background.js object returned bg.test (); chrome.tabs.query ( Active {: to true , currentWindow: to true }, function (tab) { // get the current tab // to send a request tab chrome.tabs.sendMessage (tab [ 0 ] .id, { Action: " send " , keyword: " key the word " }, function (Response) { the console.log (Response); }); }); })
code, as test.js
Such test.js can communicate with the background.js
ps:background.js
Global variables will not be destroyed in the browser is running.
Click the pop-up is not a test? ?