JavaScript Events with postMessage

When our browser-based eID workflows are run in an HTML iframe, it is good to set up an event listener on the parent window, to get a JS-event notification when the login workflow is completed either with a success or an error.

See MDN Mozilla Developer Network – Window.postMessage()

The event.data contains an object as below, where command will always be set to ‘zignsec_postback’.

Setup Eventlistener

HTML and Javascript example:

            <div id="event_response">Javascript Event Response: NOEVENT</div>
<div class="row">
    <script type="text/javascript">
        window.addEventListener("message", receiveMessage, false);

        function receiveMessage(event)
            var response = event.data;
            document.getElementById('event_response').innerText = "Javascript Event Response: " + response;

Event Data Returned on Cancelled Login

Json example:

   "error":"Action cancelled",

Event Data Returned on Successful Login

Json example: