1:content scripts is a script that page action will inject into a specific page
The content script in the Chrome plugin is run in a running environment called isolated world, and the script on the page does not interfere with each other, because it is not in a running environment, so it is not possible to invoke the method of script definition on the page. Of course, Google also gives a solution: http://code.google.com/chrome/extensions/content_scripts.html
Take a look at the JS referenced in code content_scripts will be executed on the page that matches matches
Run_at has Document_start | Idel | End three values selectable
{
"name": "Coffee",
"Manifest_version": 2,
"version": "1.0",
"description": "Coffee Test",
" Browser_action ": {
" Default_icon ":" Icon.png ",
" Default_title ":" My Task List ",
" Default_popup ":" Popup.html "
},
" background ": {
" page ":" Background.html "
},
" content_scripts ": [{
" Matches ": [" http://*/* "," https://*/* "],
" JS ": [" Js/jquery-1.9.1.min.js "," Js/test.js "],
" run_at ":" Document_start ",
" All_frames ": True
}],
" Permissions ": [
" Tabs "," http://*/* "," https://*/* "
]
}
Test.js
Each tab page is opened, and access to the URL specified by matches will pop up alert when the document is loaded.
Alert (' Hello ')
Note: The content script has limitations: That is, the JS file can only use variables or methods defined by other pages or content scripts
Use variables or functions defined by Web pages or by other content scripts
In addition: Content_script can also be added in the following ways
Background.html
Chrome.browserAction.onClicked.addListener (function (tab) {
chrome.tabs.executeScript (tab.id, {file: ') Jquery.min.js '});
Chrome.tabs.executeScript (tab.id, {file: ' content.js ');
});