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

lastEventId property (event)

Browser support:
Returns the identifier of the last event in case of onmessage events.
Note: The lastEventId property is supported in Firefox from version 3 and in Opera from version 10.6.
An onmessage event occurs when the postMessage method sends a message to the current window. The lastEventId property is not filled by the postMessage method.
If you want to set the lastEventId property, then create an event object with the createEvent method with a type of 'MessageEvent', initialize it with the initMessageEvent method and dispatch it with the dispatchEvent method.
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 the identifier of the last event.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the lastEventId property:
    <script type="text/javascript">
        function Init () {
            if (window.addEventListener) {
                window.addEventListener ("message", OnMessage, false);

        function GetState () {
            if (document.createEvent) {
                var frame = document.getElementById ("myFrame");

                    // send the 'getstate' message to the frame window
                    // use the dispatchEvent instead of the postMessage method
                var messageEvent = null;
                try {
                    messageEvent = document.createEvent('MessageEvent');
                catch (e) {
                    alert ("Your browser does not support the createEvent method for the MessageEvent event type!");

                var message = "getstate";
                var origin = window.location.protocol + "//" +;
                var lastEventId = 12;
                if (messageEvent.initMessageEvent) {
                    messageEvent.initMessageEvent ("message", true, true, message, origin, lastEventId, window, null);
                    frame.contentWindow.dispatchEvent (messageEvent);
                else {
                    alert ("Your browser does not support the initMessageEvent method!");
            else {
                alert ("Your browser does not support the createEvent 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