如何使谷歌浏览器扩展示例工作? [英] How to make Google Chrome extension sample work?

查看:92
本文介绍了如何使谷歌浏览器扩展示例工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我决定编写一个非常简单的谷歌浏览器扩展程序。它所要做的就是当用户按下扩展按钮时,使用JavaScript来隐藏网页中的一些DOM元素。



因为我对Chrome扩展一无所知,所以我开始阅读教程,并且我遇到了这个Google的示例:浏览器动作没有使页面变红的图标



这个示例非常接近我想要制作的内容。问题是我无法完成工作。无论何时我在Chrome中加载扩展程序,都可以看到此扩展程序的按钮,但是当按下它时 - 什么也没有发生。示例不起作用,可能我应该知道一些我还不知道的东西。



在你开始问我之前:




  • 是的,我尝试重新启动浏览器;
  • 我使用最新版本的Chrome。

>

感谢您的帮助。

解决方案

。找到backgrond.js ...编辑。
找到这样一行:

  null,{code:document.body.style.background ='red !重要'}); 

并删除!important。所以它应该阅读:

  null,{code:document.body.style.background ='red'}); 

就是这样。只是保存并重新加载扩展名,应该工作(除非页面有一个重要的标志设置为背景)。

恐怕我不知道为什么 !重要标签不起作用,但我从来没有能够在扩展中使用它。希望这里的其他人能够给出解释,也许还有解决办法。


Recently I decided to write a very simple Google Chrome extension. All it's going to do is to hide some DOM-elements from the web-page using JavaScript when user presses the extension's button.

Since I knew nothing about Chrome extensions, I started reading tutorials, and I came across this Google's sample: A browser action with no icon that makes the page red

This sample is really close to what I want to make. The problem is that I can't make it work. Whenever I load the extension in Chrome, I can see the button of this extension, but when I press it - nothing happens. Sample doesn't work, probably I should know something I don't know yet.

And before you started asking me:

  • Yes, I tried restarting the browser;
  • I use the newest version of Chrome.

Thanks for help.

解决方案

If you open up the sample zip... find backgrond.js... edit. Find the line that says:

null, {code:"document.body.style.background='red !important'"});

and remove the "!important". so it should read:

null, {code:"document.body.style.background='red'"});

That is it. just save and reload the extension, should work (unless the page has an !important flag set to the background).

I am afraid I don't know why the "!important" tag doesn't work but I have never been able to get it to work in an extension. Hopefully someone else here will be able to give an explanation and maybe a work around.

这篇关于如何使谷歌浏览器扩展示例工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆