Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Internet Explorer
Web Applications
HTML5 Web Messaging
Methods
 postMessage method
postMessage method

[This documentation is preliminary and is subject to change.]

Sends a message on a MessageChannel.

Syntax

object.postMessage(msg, ports)

Parameters

msg [in]
ports [in]

If a given port is provided, that port will be used.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

If the ports parameter is supplied but contains errors, a INVALID_STATE_ERROR exception will be thrown.

 

 

Build date: 2/7/2012

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
the sample is incorrect      Dean Justus   |   Edit   |   Show History
The sample is missing the second parameter. Should be something like:

o.contentWindow.postMessage('Hello World', "*");

Without the second parameter IE8 RTM will fail with a javascript error: 'invalid argument'.
Tags What's this?: Add a tag
Flag as ContentBug
Don't use "typeof(window.postMessage)" to determine whether a browser supports the HTML5 postMessage      smartgk   |   Edit   |   Show History
Don't use "typeof(window.postMessage)" to determine whether a browser supports the HTML5 postMessage feature - both Internet Explorer 6 and 7 return a value of "function" as the type!
It appears as though IE7 have some sort of undocumented function called postMessage that has a completely different purpose. It could cause conflicts if you're not careful when calling this function. In IE7 typeof(window.postMessage) returns 'object' Ref: http://gold-king.appspot.com/static/post-message-test.html
- Thangaraju Ramasamy
Tags What's this?: Add a tag
Flag as ContentBug
Warning about feature detection with IE6 and IE7      Shadow Chaser ... smartgk   |   Edit   |   Show History
Don't use "typeof(window.postMessage)" to determine whether a browser supports the HTML5 postMessage feature - both Internet Explorer 6 and 7 return a value of "function" as the type!

It appears as though IE6 and IE7 have some sort of undocumented function called postMessage that has a completely different purpose. It could cause conflicts if you're not careful when calling this function.

[Is there a reference or test for this? All my tests have shown this to NOT be the case, IE6 and 7 return "undefined"]

In IE7 typeof(window.postMessage) returns 'object' Ref: http://gold-king.appspot.com/static/post-message-test.html

IE8 does not allow postMessage across windows/tabs      EricLaw-MSFT   |   Edit   |   Show History
Tags What's this?: Add a tag
Flag as ContentBug
deviation from the HTML 5 spec      Steve Souders ... EricLaw-MSFT   |   Edit   |   Show History

IE 8 Beta1 included this feature before the HTML5 proposal was changed. The IE8 Beta2 build will be updated to comply with the current HTML5 proposal.

This sample page demonstrates that IE8 Beta 1( I'm running 8.0.6001.17184 ) deviates significantly from the HTML5 spec for postMessage:

http://stevesouders.com/misc/test-postmessage.php

The specific issues:
  • The HTML 5 spec says, "If the value of the targetOrigin argument is neither a single U+002A ASTERISK character ("*") nor a valid URI or IRI, then throw a SYNTAX_ERR exception...". IE8 doesn't thrown an exception when the second parameter is missing.
  • The HTML 5 spec says, "If the value of the targetOrigin argument is neither a single U+002A ASTERISK character ("*") nor a valid URI or IRI, then throw a SYNTAX_ERR exception...". Even though "*" is valid according to the spec, IE8 still throws an exception and aborts.
  • The HTML 5 spec says, "When a script invokes the postMessage(message, targetOrigin) method on a Window object,...". But postMessage only works when it's attached to the document object in IE8.


  • Tags What's this?: Add a tag
    Flag as ContentBug
    Processing
    © 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
    Page view tracker