Monday, June 3, 2024
79
rated 0 times [  86] [ 7]  / answers: 1 / hits: 28459  / 11 Years ago, fri, october 4, 2013, 12:00:00

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 ?


More From » google-chrome

 Answers
13

updated:


According the browserAction 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();

[#75229] Thursday, October 3, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brynneg

Total Points: 205
Total Questions: 111
Total Answers: 112

Location: Djibouti
Member since Wed, Dec 8, 2021
3 Years ago
;