当用户点击我的扩展程序图标时,我想显示一个简单的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
事件?
答案 0 :(得分:7)
<强>更新强>
根据documention,它就像:
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();