关于chrome:谷歌插件设置页面背景

次要步骤
1.manifest.json中申明web_accessible_resources

"web_accessible_resources":[
    "img/*"
]

2.在background中创立contextMenus并监听点击事件

var menuItem = {
    "id" : "resource",
    "title": "设置背景图",
    "contexts": ["all"]
};
chrome.contextMenus.create(menuItem);

3.调用chrome.extension.getURL获取图片URL

var imgurl = chrome.extension.getURL("img/beauty.jpg");

4.调用executeScript

chrome.tabs.executeScript(null,{code:"document.body.style.backgroundImage = 'url(\""+imgurl+"\")';\
    document.body.style.backgroundRepeat='repeat';"});

源码
链接:https://pan.baidu.com/s/1p3wk…
提取码:ond1

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理