在Chrome扩展中显示警报对话框 [英] Show alert dialog in chrome extension

查看:153
本文介绍了在Chrome扩展中显示警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击我的扩展程序图标时,我想显示简单的警报。我试过这段代码: chrome.browserAction.onClicked.addListener(
alert(1)
);

这里是我的 manifest

  {
manifest_version:2,

name:sample,
description:des,
version:1.0,
$ bbrowser_action :{
default_icon:icon.png
},
权限:[
]
}



如何显示alert onClick事件? p> 更新:



根据文档就像这样:

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

这里是谷歌示例(zip文件)

  //版权所有(c)2011 The Chromium Authors。版权所有。 
//使用此源代码由BSD样式的许可证管理,该许可证可以是LICENSE文件中的
//。

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();


I want to display simple alert when user clicks on my extension icon. I have tried this code :chrome.browserAction.onClicked.addListener( alert(1) ); , here is my manifest :

{
  "manifest_version": 2,

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

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

How do I show alert onClick event ?

解决方案

updated:

According the documention it is like:

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

and here is the 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();

这篇关于在Chrome扩展中显示警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆