Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 752373 of UserDataHandler

  • Revision slug: Web/API/UserDataHandler
  • Revision title: UserDataHandler
  • Revision id: 752373
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment group

Revision Content

{{APIRef("DOM")}}

{{obsolete_header(26)}}

Summary

When associating user data with a key on a node, Node.setUserData() can also accept, in its third argument, a handler which will be called when the object is cloned, imported, deleted, renamed, or adopted. Per the specification, exceptions should not be thrown in a UserDataHandler. In both document.importNode() and Node.cloneNode(), although user data is not copied over, the handler will be called.

Properties

None.

Methods

handle (operation, key, data, src, dst) (no return value)

This method is a callback which will be called if a node is being cloned, imported, renamed and as well, if deleted or adopted.

  • operation (unsigned short) is an operation type integer (see below).
  • key ({{ domxref("DOMString") }}) is the user key.
  • data ({{ domxref("DOMUserData") }}) is the user data.
  • src ({{ domxref("Node") }}) is the source node (null if being deleted).
  • dst ({{ domxref("Node") }}) is the destination node (if any, or null).

Constants

Constant Value Operation
NODE_CLONED 1 Node.cloneNode()
NODE_IMPORTED 2 Document.importNode()
NODE_DELETED {{ unimplemented_inline("550400") }} 3  
NODE_RENAMED {{ unimplemented_inline() }} 4 Node.renameNode()
NODE_ADOPTED 5 Document.adoptNode()

(NODE_RENAMED is currently not supported since Node.renameNode() is not supported.)

Specification

DOM Level 3 Core: UserDataHandler

See also

Revision Source

<p>{{APIRef("DOM")}}</p>

<p>{{obsolete_header(26)}}</p>

<h2 id="Summary">Summary</h2>

<p>When associating user data with a key on a node, <code><a class="internal" href="/En/DOM/Node.setUserData" title="En/DOM/Node.setUserData">Node.setUserData</a>()</code> can also accept, in its third argument, a handler which will be called when the object is cloned, imported, deleted, renamed, or adopted. Per the specification, exceptions should not be thrown in a <code>UserDataHandler</code>. In both <code><a class="internal" href="/en/DOM/document.importNode" title="En/DOM/document.importNode">document.importNode</a>()</code> and <code><a class="internal" href="/En/DOM/Node.cloneNode" title="En/DOM/Node.cloneNode">Node.cloneNode</a>()</code>, although user data is not copied over, the handler will be called.</p>

<h2 id="Properties">Properties</h2>

<p>None.</p>

<h2 id="Methods">Methods</h2>

<p><code>handle (operation, key, data, src, dst)</code> (no return value)</p>

<p>This method is a callback which will be called if a node is being cloned, imported, renamed and as well, if deleted or adopted.</p>

<ul>
 <li><code>operation</code> (unsigned short) is an operation type integer (see below).</li>
 <li><code>key</code> ({{ domxref("DOMString") }}) is the user key.</li>
 <li><code>data</code> ({{ domxref("DOMUserData") }}) is the user data.</li>
 <li><code>src</code> ({{ domxref("Node") }}) is the source node (<code>null</code> if being deleted).</li>
 <li><code>dst</code> ({{ domxref("Node") }}) is the destination node (if any, or <code>null</code>).</li>
</ul>

<h2 id="Constants">Constants</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th>Constant</th>
   <th>Value</th>
   <th>Operation</th>
  </tr>
  <tr>
   <td><code>NODE_CLONED</code></td>
   <td>1</td>
   <td><code><a href="/En/DOM/Node.cloneNode" title="En/DOM/Node.cloneNode">Node.cloneNode</a>()</code></td>
  </tr>
  <tr>
   <td><code>NODE_IMPORTED</code></td>
   <td>2</td>
   <td><code><a href="/en/DOM/document.importNode" title="En/DOM/Document.importNode">Document.importNode</a>()</code></td>
  </tr>
  <tr>
   <td><code>NODE_DELETED</code> {{ unimplemented_inline("550400") }}</td>
   <td>3</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td><code>NODE_RENAMED</code> {{ unimplemented_inline() }}</td>
   <td>4</td>
   <td><code><a href="/En/DOM/Node.renameNode" title="En/DOM/Node.renameNode">Node.renameNode</a>()</code></td>
  </tr>
  <tr>
   <td><code>NODE_ADOPTED</code></td>
   <td>5</td>
   <td><code><a href="/en/DOM/document.adoptNode" title="En/DOM/document.adoptNode">Document.adoptNode</a>()</code></td>
  </tr>
 </tbody>
</table>

<p>(<code>NODE_RENAMED</code> is currently not supported since <code><a href="/En/DOM/Node.renameNode" title="En/DOM/Node.renameNode">Node.renameNode</a>()</code> is not supported.)</p>

<h2 id="Specification">Specification</h2>

<p><a class="external" href="https://www.w3.org/TR/DOM-Level-3-Core/core.html#UserDataHandler">DOM Level 3 Core: UserDataHandler</a></p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/En/DOM/DOMUserData" title="En/DOM/DOMUserData"><code>DOMUserData</code></a></li>
 <li><a href="/En/DOM/Node.getUserData" title="En/DOM/Node.getUserData"><code>Node.getUserData</code></a>, <a href="/En/DOM/Node.setUserData" title="En/DOM/Node.setUserData"><code>Node.setUserData</code></a></li>
</ul>
Revert to this revision