【问题标题】:How to change badge text for chrome extension when the icon is clicked?单击图标时如何更改 chrome 扩展的徽章文本?
【发布时间】:2015-04-28 14:06:03
【问题描述】:

我是开发 chrome 扩展的新手,想从一些简单的代码开始。当用户单击图标时,我尝试更改徽章文本。但是,这似乎不起作用。谁能建议我在这里做错了什么?

manifest.json

  {
  "name": "Hello World",
  "description": "Just displays hello world",
  "version": "1.2",
  "manifest_version": 2,
  "background": 
    {
        "scripts": ["background.js"],
        "persistent": false
    },
  "browser_action":
    {
        "name": "Click to display",
        "default_popup": "popup.html"

    }

 }

background.js

function updatebadge()
{
chrome.browserAction.setBadgeText({text: "Hello!"});    
};

chrome.browserAction.onClicked.addListener(updatebadge);

popup.html

<body>
    Hello, World!
</body>

【问题讨论】:

    标签: javascript google-chrome google-chrome-extension


    【解决方案1】:

    根据chrome.browserAction

    点击

    单击浏览器操作图标时触发。如果浏览器操作有弹出窗口,则不会触发此事件。

    因此您可以删除弹出窗口,或使用解决方法...

    chrome.browserAction.onClicked.addListener() with popup

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多