【问题标题】:Css background file inside of Chrome Ex. spilling over and affecting css on normal webpagesChrome Ex 中的 Css 背景文件。溢出并影响普通网页上的 CSS
【发布时间】:2011-08-05 23:26:41
【问题描述】:

我正在开发一个 chrome 扩展,我最近将所有 css 从 popup.html 文件中移动到一个新的 .css 文件中,以尝试清理一些代码。

嗯,当我们进行测试时,我们开始在我们经常访问的一些网页上看到一些有趣的行为,并且需要一些时间才能将其与扩展程序连接起来。一旦我们这样做了,我做了一些挖掘并意识到我的 css 中的 css 标签与受影响页面上的标签相同,并且我的 css 覆盖了页面上的 css。

我在谷歌和堆栈上环顾四周,似乎我是唯一一个遇到这个问题的人。任何人都知道为什么会发生这种情况。

---编辑---

对不起,我应该更具体一点,我确实使用了 chrome 文档站点上描述的程序注入,这是我的清单和我的 popup.html 文件头的一部分:

Manifest.json 文件

     {
       "background_page": "background.html",
       "browser_action": {
       "default_icon": "loggedout.png",
       "popup": "popup.html"
     },
       "content_scripts": [ {
       "js": [ "content/overlay.js",
       "content/jquery.js","content/jquery.watermark.min.js"],
       "css": ["popup.css"],
       "matches": [ "http://*/*", "https://*/*" ],
       "run_at": "document_start"
      } ],

Popup.html 文件

      <html>
         <head>
            <link rel="stylesheet" href="popup.css" type="text/css">
            ....... other includes
         </head>

【问题讨论】:

  • 你能更详细地描述一下你移动了那些css吗?进入清单?您在说哪个弹出窗口 - 浏览器操作弹出窗口?

标签: css google-chrome google-chrome-extension


【解决方案1】:

只需从清单中删除 "css": ["popup.css"], 行,不需要它。您可以在弹出窗口中包含任何本地 css,而无需在清单中描述(清单中的 css 仅用于内容脚本)。

【讨论】:

    【解决方案2】:

    除非您希望将您的 css 注入到您的扩展目标的每个页面中,否则您必须使用此处所述的编程注入:

    http://code.google.com/chrome/extensions/content_scripts.html

    【讨论】:

      猜你喜欢
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 1970-01-01
      相关资源
      最近更新 更多