gpt4 book ai didi

javascript - 单击图标时如何更改 chrome 扩展的徽章文本?

转载 作者:行者123 更新时间:2023-11-28 19:15:39 26 4
gpt4 key购买 nike

我是开发 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>

最佳答案

根据chrome.browserAction

onClicked

Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.

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

chrome.browserAction.onClicked.addListener() with popup

关于javascript - 单击图标时如何更改 chrome 扩展的徽章文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29911329/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com