mozilla
Your Search Results

    addTab

    The BrowserApp object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

    Summary

    BrowserApp.addTab() opens a new tab. By default, the new tab is made the selected tab.

    Syntax

    var tab = window.BrowserApp.addTab(uri);

    var tab = window.BrowserApp.addTab(uri, params);

    uri
    The URI to load into the tab, represented as a string.
    params
    An optional parameter which contains any of these properties:
    • pinned: boolean property, true if you want the new tab to be pinned as an app tab. Defaults to false.
    • selected: boolean property, true if you want the new tab to be made the selected tab. Defaults to true.
    • isPrivate New in Mobile 20: boolean property, true if you want the new tab to be opened in private browsing mode. [This editor's note: in my tests, defaulted to false]

    Returns

    tab: the new tab, represented as a Tab object.

    Example

    This code implements a simple "View Source" add-on, using BrowserApp.addTab() to open a new tab displaying the current tab's source:

    function viewSource(window) {
      window.BrowserApp.addTab("view-source:" + window.content.location.href);
    }
    
    var menuId;
    
    function loadIntoWindow(window) {
      if (!window)
        return;
      menuId = window.NativeWindow.menu.add("View Source", null, function() {
        viewSource(window);
     });
    }
    
    function unloadFromWindow(window) {
      if (!window)
        return;
      window.NativeWindow.menu.remove(menuId);
    }
    

    This function opens the specified uri in a new tab, without selecting the tab:

    function openUnselected(window, uri) {
      let params = {
        selected: false
      };
      window.BrowserApp.addTab(uri, params);
    }
    

    See Also

    Document Tags and Contributors

    Contributors to this page: wbamberg, Tobias Schmidbauer
    Last updated by: wbamberg,
    Hide Sidebar