在chrome扩展中显示提醒对话框

5t7ly7z5  于 2023-03-27  发布在  Go
关注(0)|答案(1)|浏览(240)

我想在用户点击我的扩展图标时显示一个简单的alert。我已经尝试过以下代码:

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

下面是我的manifest

{
  "manifest_version": 2,

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

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

如何显示警报onClick事件?

b4lqfgs4

b4lqfgs41#

更新时间:

根据browserAction 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();

相关问题