谷歌插件(设置页面背景)
文章目录
主要步骤
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
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论