2011-12-04 89 views
0

我有这个扩展名,使打开的选项卡中的样式更改.. 我打电话给注入js文件的背景页面。 这个文件包含一个点击事件的监听器,当点击时,改变开始。 这里是JS:注入内容脚本

chrome.browserAction.onClicked.addListener(function() { 
    alert(1); 
}); 

该文件对我的作品,但是当我用这个替代它:

chrome.browserAction.onClicked.addListener(function() { 
    chrome.tabs.executeScript(null, 
    {code:"document.body.bgColor='red !important'"}); 
}); 

它不工作.. 没有任何理由是什么?

这里是mainfest.json:

{ 
    "name": "My First Extension", 
    "version": "1.0", 
    "background_page": "background1.html" , 
    "description": "The first extension that I made.", 
    "browser_action": { 
    "default_icon": "icon.png" 
    }, 
    "content_scripts": [ 
    { 
     "matches": ["http://*/*"] 
     ,"css": ["css/style.css"] 
     ,"js": ["js/jquery-1.3.2.min.js", "js/functions.js"] 
    } 
    ] 
    , 
    "permissions": [ 
    "tabs", "http://*/*","https://*/*" 
    ] 
} 

回答

0

您是否尝试注入"document.body.style.backgroundColor='red !important'"而不是"document.body.bgColor='red !important'"