- From: poot <cvsmail@w3.org>
- Date: Tue, 15 Jul 2008 20:04:44 +0900 (JST)
- To: public-html-diffs@w3.org
Correct example for postMessage(). (credit: avk) (whatwg r1876) (changed by: Ian Hickson) Diffs for this change per section: 7.4.1 Introduction http://people.w3.org/mike/diffs/html5/spec/Overview.1.1065.html#introduction5 Current content per affected section: http://dev.w3.org/html5/spec/Overview.html#introduction5 Previously published WD content per affected section: http://www.w3.org/TR/2008/WD-html5-20080610/single-page/#introduction5 Cumulative diff: http://people.w3.org/mike/diffs/html5/spec/Overview.diff.html http://dev.w3.org/cvsweb/html5/spec/Overview.html?r1=1.1064&r2=1.1065&f=h http://html5.org/tools/web-apps-tracker?from=1875&to=1876 =================================================================== RCS file: /sources/public/html5/spec/Overview.html,v retrieving revision 1.1064 retrieving revision 1.1065 diff -u -d -r1.1064 -r1.1065 --- Overview.html 15 Jul 2008 10:40:36 -0000 1.1064 +++ Overview.html 15 Jul 2008 10:45:45 -0000 1.1065 @@ -42290,20 +42290,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') {
Received on Tuesday, 15 July 2008 11:05:26 UTC