gpt4 book ai didi

javascript - 在 chrome 扩展程序中显示警报对话框

转载 作者:数据小太阳 更新时间:2023-10-29 05:15:48 27 4
gpt4 key购买 nike

我想在用户点击我的扩展程序图标时显示一个简单的警告。我试过这段代码:

chrome.browserAction.onClicked.addListener(
alert(1)
);

这是我的 list :

{
"manifest_version": 2,

"name": "sample",
"description": "des",
"version": "1.0",

"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
]
}

如何显示警报 onClick 事件?

最佳答案

更新:

根据documentation就像:

chrome.browserAction.onClicked.addListener(function() { 
alert('Hello, World!');
})

这里是 sample from Google (zip-file) :

// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var min = 1;
var max = 5;
var current = min;

function updateIcon() {
chrome.browserAction.setIcon({path:"icon" + current + ".png"});
current++;

if (current > max)
current = min;
}

chrome.browserAction.onClicked.addListener(updateIcon);
updateIcon();

关于javascript - 在 chrome 扩展程序中显示警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19177216/

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