Chrome 扩展:如何使用 contextMenus 修改确定页面的 DOM?

发布于 2025-01-08 08:57:38 字数 1106 浏览 1 评论 0原文

作为标题,如何能够将修改应用到与背景不同的另一个页面?

清单:

{
    "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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唠甜嗑 2025-01-15 08:57:38

我强烈建议阅读内容脚本

我可以使用这些技术为您提供一个快速解决方案,但您稍后可能会陷入陷阱,因为您没有研究这些页面。不过,我将为您提供一个基本的示例流程;

它比乍一看要简单得多。

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;

It's a lot simpler than it may first appear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文