Revision 400831 of UserDataHandler

  • Revision slug: Web/API/UserDataHandler
  • Revision title: UserDataHandler
  • Revision id: 400831
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment linkify some stuff; needs reformatting work still; 21 words addedDOM/UserDataHandler Web/API/UserDataHandler

Revision Content

{{ DomRef() }}

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>{{ DomRef() }}</p>
<h3 id="Summary">Summary</h3>
<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>
<h3 id="Properties">Properties</h3>
<p>None.</p>
<h3 id="Methods">Methods</h3>
<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>
<h3 id="Constants">Constants</h3>
<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> </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>
<h3 id="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#UserDataHandler">DOM Level 3 Core: UserDataHandler</a></p>
<h3 id="See_also">See also</h3>
<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