Include the following lines in your .xul file.
<script type="application/x-javascript" src="chrome://browser/content/utilityOverlay.js"/>
<script type="application/x-javascript" src="chrome://browser/content/browser.js"/>
With these 2 scripts included in your extension, you will get many useful functions for
FREE.
I found 2 functions useful for me for the current extension I am working on (Secret project... ).
whereToOpenLink(event): This function require an event object. Every event in firefox has an associated event object. For example,
<menuitem label="Click Me!" oncommand="whereToOpenLink(event);"/>
openUILinkIn(url, browserTarget): This function open the given
url in the
browserTarget. browserTarget is the return value from
whereToOpenLink function.
<menuitem label="Click Me!" oncommand="openUILinkIn('http://www.yahoo.com', whereToOpenLink(event));"/>
openPreferences(paneId): This function open the preferences window with paneId as the default tab. By default firefox has the following pane Ids.
- paneGeneral
- panePrivacy
- paneContent
- paneTabs
- paneDownloads
- paneAdvanced
For example,
<button label="Open Advanced Preferences" oncommand="openPreferences('paneAdvanced');"/>
I will post more functions as and when I find out new ones.
Till then, happy exntensioning....