Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用my chrome扩展更改google搜索页面的背景_Javascript_Css_Html_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript 使用my chrome扩展更改google搜索页面的背景

Javascript 使用my chrome扩展更改google搜索页面的背景,javascript,css,html,google-chrome,google-chrome-extension,Javascript,Css,Html,Google Chrome,Google Chrome Extension,我正在尝试创建我的第一个chrome插件,当用户点击new tab按钮时,它将以随机图片作为背景打开Google页面。到目前为止,我不太清楚,如何改变谷歌搜索页面背景与随机图像。谷歌有没有提供api?正如我在谷歌上搜索到的,早些时候谷歌有“更改背景图像”图标,但现在他们停止了这种支持。在这里,我如何改变谷歌搜索页面的背景,以不同的颜色或不同的背景图像。我尝试了以下js代码。请建议或重定向到正确的方法。任何帮助将不胜感激 window.open("http://www.google.com", "

我正在尝试创建我的第一个chrome插件,当用户点击new tab按钮时,它将以随机图片作为背景打开Google页面。到目前为止,我不太清楚,如何改变谷歌搜索页面背景与随机图像。谷歌有没有提供api?正如我在谷歌上搜索到的,早些时候谷歌有“更改背景图像”图标,但现在他们停止了这种支持。在这里,我如何改变谷歌搜索页面的背景,以不同的颜色或不同的背景图像。我尝试了以下js代码。请建议或重定向到正确的方法。任何帮助将不胜感激

window.open("http://www.google.com", "_self");
window.onload = function () {
    document.body.style.background = 'red';
};
另外,以下脚本将更改当前html页面的背景 但是如何通过注入这个来改变第三方页面的背景

<script>
function myFunction() {
    document.body.style.backgroundColor = "#f3f3f3";
    document.body.style.backgroundImage = "url('xyz.png')";
}
</script>

函数myFunction(){
document.body.style.backgroundColor=“#f3”;
document.body.style.backgroundImage=“url('xyz.png')”;
}

看起来身体在工作,你应该用元素替换它。在chrome中使用F12 inspector,可以看到背景色是用

element.style {
background: rgb(255, 255, 255);
}

如果你不想编码,那么已经有多个背景插件,还有很多主题的chrome主题插件,我确信其中一些插件可以接受自定义图像/颜色。

我自己找到了答案

window.onload = function () {
    document.body.style.backgroundImage = 'url("chrome-extension://@'+chrome.runtime.id+'/icon.png")';
};
这将为我的谷歌搜索页面加载背景图片。
谢谢。

谢谢。不过,我已经找到了我在下面发布的确切答案。除此之外,我相信现在您可能希望使用
\uuuu MSG\u@@extension\u id\uuuu