mozilla

Revision 508781 of content/mod

  • Revision slug: Mozilla/Add-ons/SDK/Low-Level_APIs/content_mod
  • Revision title: content/mod
  • Revision id: 508781
  • Created:
  • Creator: wbamberg
  • Is current revision? Yes
  • Comment

Revision Content

Experimental

Provides functions to modify a page content.

Globals

Constructors

Functions

attachTo(modification, window)

Function applies given modification to a given window.

For example, the following code applies a style to a content window, adding a border to all divs in page:

var attachTo = require("sdk/content/mod").attachTo;
var Style = require("sdk/stylesheet/style").Style;

var style = Style({
  source: "div { border: 4px solid gray }"
});

// assuming window points to the content page we want to modify
attachTo(style, window);
Parameters

modification : object
The modification we want to apply to the target.

window : nsIDOMWindow
The window to be modified.

detachFrom(modification, window)

Function removes attached modification from a given window. If window is not specified, modification is removed from all the windows it's being attached to.

For example, the following code applies and removes a style to a content window, adding a border to all divs in page:

var { attachTo, detachFrom } = require("sdk/content/mod");
var Style = require("sdk/stylesheet/style").Style;

var style = Style({
  source: "div { border: 4px solid gray }"
});

// assuming window points to the content page we want to modify
attachTo(style, window);
// ...
detachFrom(style, window);
Parameters

modification : object
The modification we want to remove from the target

window : nsIDOMWindow
The window to be modified. If window is not provided modification is removed from all targets it's being attached to.

getTargetWindow(target)

Function takes target, value representing content (page) and returns nsIDOMWindow for that content. If target does not represents valid content null is returned. For example target can be a content window itself in which case it's will be returned back.

Parameters

target : object
The object for which we want to obtain the window represented or contained. If a nsIDOMWindow is given, it works as an identify function, returns target itself.

Returns

nsIDOMWindow|null : The window represented or contained by the target, if any. Returns null otherwise.

attach(modification, target)

Function applies given modification to a given target representing a content to be modified.

Parameters

modification : object
The modification we want to apply to the target

target : object
Target is a value that representing content to be modified. It is valid only when getTargetWindow(target) returns nsIDOMWindow of content it represents.

detach(modification, target)

Function removes attached modification. If target is specified modification is removed from that target only, otherwise modification is removed from all the targets it's being attached to.

Parameters

modification : object
The modification we want to remove from the target

target : object
Target is a value that representing content to be modified. It is valid only when getTargetWindow(target) returns nsIDOMWindow of content it represents. If target is not provided modification is removed from all targets it's being attached to.

Revision Source

<div class="note">
 <p>Experimental</p>
</div>
<p><span class="seoSummary">Provides functions to modify a page content.</span></p>
<h2 id="Globals">Globals</h2>
<h3 id="Constructors">Constructors</h3>
<h3 id="Functions">Functions</h3>
<h4 class="addon-sdk-api-name" id="attachTo(modification.2C_window)"><code>attachTo(modification, window)</code></h4>
<p>Function applies given <code>modification</code> to a given <code>window</code>.</p>
<p>For example, the following code applies a style to a content window, adding a border to all divs in page:</p>
<pre class="brush: js">
var attachTo = require("sdk/content/mod").attachTo;
var Style = require("sdk/stylesheet/style").Style;

var style = Style({
  source: "div { border: 4px solid gray }"
});

// assuming window points to the content page we want to modify
attachTo(style, window);</pre>
<h5 id="Parameters">Parameters</h5>
<p><strong>modification : object</strong><br />
 The modification we want to apply to the target.</p>
<p><strong>window : nsIDOMWindow</strong><br />
 The window to be modified.</p>
<h4 class="addon-sdk-api-name" id="detachFrom(modification.2C_window)"><code>detachFrom(modification, window)</code></h4>
<p>Function removes attached <code>modification</code> from a given <code>window</code>. If <code>window</code> is not specified, <code>modification</code> is removed from all the windows it's being attached to.</p>
<p>For example, the following code applies and removes a style to a content window, adding a border to all divs in page:</p>
<pre class="brush: js">
var { attachTo, detachFrom } = require("sdk/content/mod");
var Style = require("sdk/stylesheet/style").Style;

var style = Style({
  source: "div { border: 4px solid gray }"
});

// assuming window points to the content page we want to modify
attachTo(style, window);
// ...
detachFrom(style, window);</pre>
<h5 id="Parameters">Parameters</h5>
<p><strong>modification : object</strong><br />
 The modification we want to remove from the target</p>
<p><strong>window : nsIDOMWindow</strong><br />
 The window to be modified. If <code>window</code> is not provided <code>modification</code> is removed from all targets it's being attached to.</p>
<h4 class="addon-sdk-api-name" id="getTargetWindow(target)"><code>getTargetWindow(target)</code></h4>
<p>Function takes <code>target</code>, value representing content (page) and returns <code>nsIDOMWindow</code> for that content. If <code>target</code> does not represents valid content <code>null</code> is returned. For example target can be a content window itself in which case it's will be returned back.</p>
<h5 id="Parameters">Parameters</h5>
<p><strong>target : object</strong><br />
 The object for which we want to obtain the window represented or contained. If a <code>nsIDOMWindow</code> is given, it works as an identify function, returns <code>target</code> itself.</p>
<h5 id="Returns">Returns</h5>
<p><strong>nsIDOMWindow|null</strong> : The window represented or contained by the <code>target</code>, if any. Returns <code>null</code> otherwise.</p>
<h4 class="addon-sdk-api-name" id="attach(modification.2C_target)"><code>attach(modification, target)</code></h4>
<p>Function applies given <code>modification</code> to a given <code>target</code> representing a content to be modified.</p>
<h5 id="Parameters">Parameters</h5>
<p><strong>modification : object</strong><br />
 The modification we want to apply to the target</p>
<p><strong>target : object</strong><br />
 Target is a value that representing content to be modified. It is valid only when <code>getTargetWindow(target)</code> returns nsIDOMWindow of content it represents.</p>
<h4 class="addon-sdk-api-name" id="detach(modification.2C_target)"><code>detach(modification, target)</code></h4>
<p>Function removes attached <code>modification</code>. If <code>target</code> is specified <code>modification</code> is removed from that <code>target</code> only, otherwise <code>modification</code> is removed from all the targets it's being attached to.</p>
<h5 id="Parameters">Parameters</h5>
<p><strong>modification : object</strong><br />
 The modification we want to remove from the target</p>
<p><strong>target : object</strong><br />
 Target is a value that representing content to be modified. It is valid only when <code>getTargetWindow(target)</code> returns <code>nsIDOMWindow</code> of content it represents. If <code>target</code> is not provided <code>modification</code> is removed from all targets it's being attached to.</p>
Revert to this revision