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

domain property (event)

Browser support:
9.5
10
Returns the hostname of the server that served the document that caused the onmessage event.
Note: The support for the domain and domain properties has been removed in Opera 10. In Firefox, Google Chrome, Safari, Internet Explorer from version 8 and Opera from version 10, use the origin property instead.
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:

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

Possible values:

String that retrieves the domain.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the domain property:
Code
message.htm
<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? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content