Chrome 扩展:如何使用 contextMenus 修改确定页面的 DOM?
作为标题,如何能够将修改应用到与背景不同的另一个页面?
清单:
{
"name": "First Extension",
"version": "1.0",
"description": "The first extensione tha I made",
"permissions":["contextMenus", "tabs", "http://localhost/CreativaIly/*"],
"background_page": "background_page.html",
"browser_action":{
"name": "My First Extension!",
"default_icon": "Chrome_icon32bn.png",
/*"default_popup": "popup.html",*/
"default_title": "My First Extension!"
},
"icons": {
"16": "Chrome_icon19color.png",
"48": "Chrome_icon32color.png",
"128": "Chrome_icon.png"
}
}
背景页:
<!doctype html>
<html>
<head>
<title>Background Page</title>
<script type="text/javascript" src="mootools-core-1.4.2-full-compat.js"></script>
<script src="script.js" type="text/javascript" ></script>
</head>
<body>
</body>
</html>
As title, how to be able to apply the modifications to another page, different from that of background?
Manifest:
{
"name": "First Extension",
"version": "1.0",
"description": "The first extensione tha I made",
"permissions":["contextMenus", "tabs", "http://localhost/CreativaIly/*"],
"background_page": "background_page.html",
"browser_action":{
"name": "My First Extension!",
"default_icon": "Chrome_icon32bn.png",
/*"default_popup": "popup.html",*/
"default_title": "My First Extension!"
},
"icons": {
"16": "Chrome_icon19color.png",
"48": "Chrome_icon32color.png",
"128": "Chrome_icon.png"
}
}
Background page:
<!doctype html>
<html>
<head>
<title>Background Page</title>
<script type="text/javascript" src="mootools-core-1.4.2-full-compat.js"></script>
<script src="script.js" type="text/javascript" ></script>
</head>
<body>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈建议阅读内容脚本和
我可以使用这些技术为您提供一个快速解决方案,但您稍后可能会陷入陷阱,因为您没有研究这些页面。不过,我将为您提供一个基本的示例流程;
tab.id
并使用它来调用 chrome.tabs.sendRequest它比乍一看要简单得多。
I strongly recommend reading about content scripts and message passing as the solution involves the combination of these 2 techniques.
I could do a quick solution for you using these techniques but you'd probably fall in to a pitfall later on because you didn't study these pages. However, I will give you a basic example flow;
tab.id
and use it to call chrome.tabs.sendRequestIt's a lot simpler than it may first appear.