mozilla

Revision 508937 of frame/hidden-frame

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/frame_hidden-frame
  • Revision title: frame/hidden-frame
  • Revision id: 508937
  • Created:
  • Creator: wbamberg
  • Is current revision? No
  • Comment

Revision Content

Experimental

Creates Firefox frames (i.e. XUL <iframe> elements) that are not displayed to the user. This is useful in the construction of APIs that load web content not intended to be directly seen or accessed by users, like page-worker. It is also useful in the construction of APIs that load web content for intermittent display, such as panel.

Usage

The module exports a constructor function, HiddenFrame, and two other functions, add and remove.

HiddenFrame constructs a new hidden frame. add registers a hidden frame, preparing it to load content. remove unregisters a frame, unloading any content that was loaded in it.

The following code creates a hidden frame, loads a web page into it, and then logs its title:

var hiddenFrames = require("sdk/frame/hidden-frame");
let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
  onReady: function() {
    this.element.contentWindow.location = "http://www.mozilla.org/";
    let self = this;
    this.element.addEventListener("DOMContentLoaded", function() {
      console.log(self.element.contentDocument.title);
    }, true, true);
  }
}));

See the panel module for a real-world example of usage of this module.

Globals

Constructors

HiddenFrame(options)

Creates a hidden frame.

Parameters

options : object
Required options:

Name Type  
onReady function,array

Functions to call when the frame is ready to load content. You must specify an onReady callback and refrain from using the hidden frame until the callback gets called, because hidden frames are not always ready to load content the moment they are added.

Functions

add(hiddenFrame)

Register a hidden frame, preparing it to load content.

Parameters

hiddenFrame : HiddenFrame
the frame to add

remove(hiddenFrame)

Unregister a hidden frame, unloading any content that was loaded in it.

Parameters

hiddenFrame : HiddenFrame
the frame to remove

HiddenFrame

Properties

element

The host application frame in which the page is loaded.

Events

ready

This event is emitted when the DOM for a hidden frame content is ready. It is equivalent to the DOMContentLoaded event for the content page in a hidden frame.

Revision Source

<div class="note">
 <p>Experimental</p>
</div>
<p><span class="seoSummary">Creates Firefox frames (i.e. XUL <code>&lt;iframe&gt;</code> elements) that are not displayed to the user</span>. This is useful in the construction of APIs that load web content not intended to be directly seen or accessed by users, like <a href="modules/sdk/page-worker.html"><code>page-worker</code></a>. It is also useful in the construction of APIs that load web content for intermittent display, such as <a href="modules/sdk/panel.html"><code>panel</code></a>.</p>
<h2>Usage</h2>
<p>The module exports a constructor function, <code>HiddenFrame</code>, and two other functions, <code>add</code> and <code>remove</code>.</p>
<p><code>HiddenFrame</code> constructs a new hidden frame. <code>add</code> registers a hidden frame, preparing it to load content. <code>remove</code> unregisters a frame, unloading any content that was loaded in it.</p>
<p>The following code creates a hidden frame, loads a web page into it, and then logs its title:</p>
<pre class="brush: js">
var hiddenFrames = require("sdk/frame/hidden-frame");
let hiddenFrame = hiddenFrames.add(hiddenFrames.HiddenFrame({
  onReady: function() {
    this.element.contentWindow.location = "http://www.mozilla.org/";
    let self = this;
    this.element.addEventListener("DOMContentLoaded", function() {
      console.log(self.element.contentDocument.title);
    }, true, true);
  }
}));</pre>
<p>See the <code>panel</code> module for a real-world example of usage of this module.</p>
<h2>Globals</h2>
<h3>Constructors</h3>
<h4 class="addon-sdk-api-name"><code>HiddenFrame(options)</code></h4>
<p>Creates a hidden frame.</p>
<h5>Parameters</h5>
<p><strong>options : object</strong><br />
 Required options:</p>
<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Name</th>
   <th scope="col">Type</th>
   <th scope="col">&nbsp;</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>onReady</td>
   <td>function,array</td>
   <td>
    <p>Functions to call when the frame is ready to load content. You must specify an <code>onReady</code> callback and refrain from using the hidden frame until the callback gets called, because hidden frames are not always ready to load content the moment they are added.</p>
   </td>
  </tr>
 </tbody>
</table>
<h3>Functions</h3>
<h4 class="addon-sdk-api-name"><code>add(hiddenFrame)</code></h4>
<p>Register a hidden frame, preparing it to load content.</p>
<h5>Parameters</h5>
<p><strong>hiddenFrame : HiddenFrame</strong><br />
 the frame to add</p>
<h4 class="addon-sdk-api-name"><code>remove(hiddenFrame)</code></h4>
<p>Unregister a hidden frame, unloading any content that was loaded in it.</p>
<h5>Parameters</h5>
<p><strong>hiddenFrame : HiddenFrame</strong><br />
 the frame to remove</p>
<h2>HiddenFrame</h2>
<h3>Properties</h3>
<h4 class="addon-sdk-api-name"><code>element</code></h4>
<p>The host application frame in which the page is loaded.</p>
<h3>Events</h3>
<h4 class="addon-sdk-api-name"><code>ready</code></h4>
<p>This event is emitted when the DOM for a hidden frame content is ready. It is equivalent to the <code>DOMContentLoaded</code> event for the content page in a hidden frame.</p>
Revert to this revision