source property (event)
8 | 3 | 9.5 | ||
Returns a reference to the window object that contains the document that caused the onmessage event.
Note: The source property is supported in Internet Explorer from version 8, in Firefox from version 3 and in Opera from version 9.5.
An onmessage event occurs when the postMessage method sends a message to the current window.
For details, see the pages for the postMessage method and the onmessage event.Syntax:
You can find the related objects in the Supported by objects section below.
This property is read-only.
Possible values:
String that retrieves a reference to the caller window object.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the source property:
|
|||||
<head> <script type="text/javascript"> function Init () { if (window.addEventListener) { // all browsers except IE before version 9 window.addEventListener ("message", OnMessage, false); } else { if (window.attachEvent) { // IE before version 9 window.attachEvent("onmessage", OnMessage); } } } function GetState () { var frame = document.getElementById ("myFrame"); // send the 'getstate' message to the frame window var message = "getstate"; if (frame.contentWindow.postMessage) { frame.contentWindow.postMessage (message, "*"); } else { alert ("Your browser does not support the postMessage method!"); } } function OnMessage (event) { var message = event.data; var arr = message.split (","); if (arr[0] == "true") { alert ("The check box is checked."); } else { alert ("The check box is not checked."); } var selIndex = Number (arr[1]); alert ("The " + (selIndex + 1) + ". option is selected."); } </script> </head> <body onload="Init ();"> <iframe id="myFrame" src="message.htm" width="500" height="200px"></iframe> <br /><br /> <button onclick="GetState ()">Get the state of controls in the frame</button> </body> |
|||||
|
|||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments