You are here: Reference > JavaScript > client-side > event handling > properties > origin (event)

origin property (event)

Browser support:
Returns the scheme, hostname and port of the document that caused the onmessage event.
An onmessage event occurs when the postMessage method sends a message to the current window.
Note: The origin property is supported in Firefox from version 3 and Internet Explorer from version 8.
Note: The origin property is supported in Opera from version 10. In earlier versions, it supports the uri and domain properties instead. In Opera 10, the support for the uri and domain properties has been removed.
For further details, see the pages for the postMessage method and the onmessage event.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

String that retrieves scheme, hostname and port.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the origin property:
    <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 =;
            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.");
<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>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content