10

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事件?

4

1 回答 1

11

更新:

根据文档,它是这样的:

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

这是来自 Google 的示例(zip 文件)

// 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();
于 2013-10-04T09:07:12.650 回答