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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19177216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 14:40:23  来源:igfitidea点击:

Show alert dialog in chrome extension

javascriptgoogle-chromegoogle-chrome-extension

提问by Mickey Tin

I want to display a simple alertwhen user clicks on my extension icon. I have tried this code :

alert当用户点击我的扩展图标时,我想显示一个简单的。我试过这个代码:

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

Here is my manifest:

这是我的manifest

{
  "manifest_version": 2,

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

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

How do I show an alert onClickevent ?

如何显示警报onClick事件?

采纳答案by CodeGroover

updated:

更新:

According the documentationit is like:

根据文档,它是这样的:

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

and here is the sample from Google (zip-file):

这是来自 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();