FUEL/0.2/API/Browser

From MozillaWiki
< FUEL‎ | 0.2‎ | API
Jump to navigation Jump to search

Sample Code:

Open, and activate, a new tab

 App.browser.open("http://google.com/").active = true;

Open, and activate, a tab just after the current tab

 var tab = App.browser.open("http://google.com/");
 App.browser.insertBefore( tab, App.browser.activeTab.next );
 tab.active = true;

or:

 var tab = App.browser.open("http://google.com/");
 tab.index = App.browser.activeTab + 1;
 tab.active = true;

Move the active tab to be the first tab

 App.browser.insertBefore( App.browser.activeTab, App.browser.tabs[0] );

or:

 App.browser.activeTab.index = 0;

Close the active tab

 App.browser.activeTab.close();

Do something when the active tab loads

 App.browser.activeTab.events.addListener( "load", function(){
   this.query("#foo div")
 });

Change the URL in the active tab

 App.browser.activeTab.url = "http://mozilla.org/";

Close all Google-related tabs

 App.browser.tabs.forEach(function(tab){
   if ( tab.url.match(/google/) )
     tab.remove();
 });

Re-use a tab, or open a new one

 var url = "http://google.com/";
 App.browser.tabs.some(function(tab){
   if ( tab.url == url )
     return tab.active = true;
 }) || App.browser.open( url ).active = true;

Stop the user from opening any new tabs

 App.browser.events.addListener( "TabOpen", function(e){
   e.target.close();
 });

Browser

Properties:

  • tabs is an Array<Tab>
  • events is an Events
  • activeTab is a Tab

Methods:

  • insertBefore( Tab, Tab )
  • append( Tab )
  • open( String ) returns a Tab

Tab

Properties:

  • browser is a Browser
  • events is an Events
  • document is a DOMDocument
  • window is a DOMWindow
  • active is a Boolean
  • next is a Tab
  • prev is a Tab
  • url is a String (Getter/Setter)
  • index is a Number (Getter/Setter)

Methods:

  • query( String ) returns an Array<DOMElement>
  • focus()
  • close()