0

I have a chrome extension where the button wont get dark when clicked:

var alreadyClicked = false;
var timer;

chrome.browserAction.onClicked.addListener(function (tab) {

        //code for when dobleclicked

        timer = setTimeout(function () {
        chrome.tabs.update({
            url: "http://url.html"
        });

        clearTimeout(timer);

        alreadyClicked = false;
    }, 250);
});

Example of buttons for the translate extension:

normal: enter image description here clicked: enter image description here

  • There's nothing in your code that will change the style of a button, you are just navigating somewhere in the current window. Also you don't need to call clearTimeout within the function parameter, it's already been called. And alraedyClicked is always false, what's the use? – cviejo Nov 23 '15 at 13:04
  • I've updated the question with a sample for the button. alreadyClicked is used in //code for when dobleclicked this is not important. –  Nov 23 '15 at 13:13
  • Use [setIcon](https://developer.chrome.com/extensions/browserAction#method-setIcon) – cviejo Nov 23 '15 at 13:15
  • That's no it. It should do it automatically –  Nov 23 '15 at 13:23
  • ...you want the button to act like a toggle button? – cviejo Nov 23 '15 at 13:58
  • Yes, but I discover that only happens when the extension has a popup. Nevertheless it would be nice to have it in mine, the toggle button. –  Nov 23 '15 at 14:00
  • Then you have to do it yourself, keep track of the state and update the icon accordingly. There's no setting that will get chrome to handle it for you. Marking this as duplicate since it's already been answered multiple times ([here](http://stackoverflow.com/questions/18528009/how-to-toggle-actions-of-a-browser-action) or [here](http://stackoverflow.com/questions/16136275/how-to-make-on-off-buttons-icons-for-a-chrome-extension)) – cviejo Nov 23 '15 at 14:07

0 Answers0