作为标题,如何将修改应用到另一个页面,不同于背景?
list :
{
"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>
最佳答案
我强烈推荐阅读 content scripts和 message passing因为解决方案涉及到这两种技术的结合。
我可以使用这些技术为您提供一个快速的解决方案,但您稍后可能会陷入陷阱,因为您没有研究这些页面。不过,我会给你一个基本的示例流程;
- 设置 list 以在 chrome.extension.onRequest 时以您想要的方式操作 DOM 的所有页面中注入(inject)内容脚本。被解雇了
- 创建您的context menu并监听点击事件
- 当onclick被触发捕获
tab.id
并使用它来调用 chrome.tabs.sendRequest
它比最初看起来要简单得多。
关于dom - Chrome 扩展 : how do I do modify DOM of a determinate page with contextMenus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9429924/