firefexx
firefexx

Reputation: 786

Access JavaScript from multiple XUL files

This is about a Firefox extension:

I have a XUL browser overlay which includes all my javascripts. Eventually a javascript function triggers the load of a xul page. This page contains a button and this button is manipulated from the same javascript which triggered the page load (i.e. set the oncommand attribute of the button dynamically so that it will execute another javascript function).

The problem is, when the button is clicked, it gives me errors. My javascript objects (the namespace, functions, etc.) are not defined. But I can't include all Javascripts again in the xul page, because I need some form of a global object.

Even if I set the button to do a simpler command which has nothing to do with my own code (i.e. gBrowser.loadURI(...)), it says gBrowser is not defined.

How can I call my javascript functions with this button?

Upvotes: 0

Views: 124

Answers (1)

Noitidart
Noitidart

Reputation: 37268

//Access JavaScript from multiple XUL files

change gBrowser to be Services.wm.getMostRecentWindow('navigator:browser').gBrowser

Another option is to create a JSM file and then addEventListener to this page when it loads. Create a JSM file. See example here on gists.github

Upvotes: 1

Related Questions