Ryan
Ryan

Reputation: 10049

Javascript: Firefox addon, calling a function inside

In my button.xul file I have this:

      <script type="application/x-javascript"
  src="chrome://mf_unblocker/content/button.js"/>

<toolbarbutton id="custom-button-1"
  label="Custom"
  tooltiptext="MAFIAAFire: Slash Unblocker!"
  oncommand="CustomButton[1]()"
  class="toolbarbutton-1 chromeclass-toolbar-additional mf_unblocker"
  />

then in my button .js file I have this:

var CustomButton = {

1: function () {
alert("test!");
  },

test: function () {alert("testing!");},

}

in the xul file this CustomButton[1] brings up the alert "test!" but if I change it to CustomButton[test] it does not bring up the alert "testing!"

why is that?? It instead gives me an error "test is not define"

Upvotes: 0

Views: 294

Answers (1)

Quentin
Quentin

Reputation: 944196

You are passing the variable test and not the string "test".

test is probably undefined

Either:

CustomButton['test']();

or

CustomButton.test();

Upvotes: 2

Related Questions