[html5] r1876 - [e] (0) Correct example for postMessage(). (credit: avk)

whatwg at whatwg.org whatwg at whatwg.org
Tue Jul 15 03:45:41 PDT 2008


Author: ianh
Date: 2008-07-15 03:45:41 -0700 (Tue, 15 Jul 2008)
New Revision: 1876

Modified:
   index
   source
Log:
[e] (0) Correct example for postMessage(). (credit: avk)

Modified: index
===================================================================
--- index	2008-07-15 10:40:02 UTC (rev 1875)
+++ index	2008-07-15 10:45:41 UTC (rev 1876)
@@ -42228,20 +42228,22 @@
 
   <div class=example>
    <p>For example, if document A contains an <code><a
-    href="#object">object</a></code> element that contains document B, and
+    href="#iframe">iframe</a></code> element that contains document B, and
     script in document A calls <code title=dom-window-postMessage-2><a
-    href="#postmessage">postMessage()</a></code> on document B, then a
-    message event will be fired on that element, marked as originating from
-    document A. The script in document A might look like:</p>
+    href="#postmessage">postMessage()</a></code> on the <code><a
+    href="#window">Window</a></code> object of document B, then a message
+    event will be fired on that object, marked as originating from the
+    <code><a href="#window">Window</a></code> of document A. The script in
+    document A might look like:</p>
 
-   <pre>var o = document.getElementsByTagName('object')[0];
+   <pre>var o = document.getElementsByTagName('iframe')[0];
 o.contentWindow.postMessage('Hello world', 'http://b.example.org/');</pre>
 
    <p>To register an event handler for incoming events, the script would use
     <code title="">addEventListener()</code> (or similar mechanisms). For
     example, the script in document B might look like:</p>
 
-   <pre>document.addEventListener('message', receiver, false);
+   <pre>window.addEventListener('message', receiver, false);
 function receiver(e) {
   if (e.origin == 'http://example.com') {
     if (e.data == 'Hello world') {

Modified: source
===================================================================
--- source	2008-07-15 10:40:02 UTC (rev 1875)
+++ source	2008-07-15 10:45:41 UTC (rev 1876)
@@ -39868,14 +39868,15 @@
 
   <div class="example">
 
-   <p>For example, if document A contains an <code>object</code>
+   <p>For example, if document A contains an <code>iframe</code>
    element that contains document B, and script in document A calls
-   <code title="dom-window-postMessage-2">postMessage()</code> on
-   document B, then a message event will be fired on that element,
-   marked as originating from document A.  The script in document A
-   might look like:</p>
+   <code title="dom-window-postMessage-2">postMessage()</code> on the
+   <code>Window</code> object of document B, then a message event will
+   be fired on that object, marked as originating from the
+   <code>Window</code> of document A.  The script in document A might
+   look like:</p>
 
-   <pre>var o = document.getElementsByTagName('object')[0];
+   <pre>var o = document.getElementsByTagName('iframe')[0];
 o.contentWindow.postMessage('Hello world', 'http://b.example.org/');</pre>
 
    <p>To register an event handler for incoming events, the script
@@ -39883,7 +39884,7 @@
    mechanisms).  For example, the script in document B might look
    like:</p>
 
-   <pre>document.addEventListener('message', receiver, false);
+   <pre>window.addEventListener('message', receiver, false);
 function receiver(e) {
   if (e.origin == 'http://example.com') {
     if (e.data == 'Hello world') {




More information about the Commit-Watchers mailing list