admin管理员组文章数量:1355703
I'm trying to change the background color of web page onLoad. But, the script is not being executed Here is my code.
manifest.json
{
"name": "Page Redder",
"description": "Make the current page red",
"version": "2.0",
"permissions": [
"activeTab"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_title": "Make this page red"
},
"manifest_version": 2
}
background.js
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'plete')
chrome.tabs.executeScript(tabId, {file:"code.js"});
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
code: 'document.body.style.backgroundColor="green"'
});
});
code.js
document.body.style.backgroundColor="red"
It is working when I click on the Extension Icon. But, code.js
is not being executed.
I'm trying to change the background color of web page onLoad. But, the script is not being executed Here is my code.
manifest.json
{
"name": "Page Redder",
"description": "Make the current page red",
"version": "2.0",
"permissions": [
"activeTab"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_title": "Make this page red"
},
"manifest_version": 2
}
background.js
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'plete')
chrome.tabs.executeScript(tabId, {file:"code.js"});
});
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
code: 'document.body.style.backgroundColor="green"'
});
});
code.js
document.body.style.backgroundColor="red"
It is working when I click on the Extension Icon. But, code.js
is not being executed.
-
3
Try to change permission from
activeTab
totabs
(see developer.chrome./extensions/tabs) – devnull69 Commented May 7, 2014 at 7:19
1 Answer
Reset to default 5use content scripts. They are much simpler than doing it directly from the background.
content scripts are automatically inserted into your new loaded tab if you use the match "matches": ["<all_urls>"]
documentation: https://developer.chrome./extensions/content_scripts
本文标签: javascriptChrome Extension Change background Color on pageLoadStack Overflow
版权声明:本文标题:javascript - Chrome Extension: Change background Color on pageLoad - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743981990a2571120.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论