Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show alert dialog in chrome extension

I want to display a 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 an alert onClick event ?

like image 256
Mickey Tin Avatar asked Oct 04 '13 09:10

Mickey Tin


People also ask

How do I get Chrome to notify me when a website is updated?

Just visit the web page that you want to monitor, click on the Page Monitor extension icon in Chrome's address bar, and select monitor this page there. That's it. The page is monitored from this point in time on and you will receive notifications whenever it is modified.


1 Answers

updated:

According the documentation 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();
like image 160
CodeGroover Avatar answered Oct 04 '22 19:10

CodeGroover