ZignSec

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>
<br/>
<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;
        }
    </script>
</div>
        

Event Data Returned on Cancelled Login

Json example:

            {
   "command":"zignsec_postback",
   "errorcode":"USER_CANCEL",
   "error":"Action cancelled",
   "token":"a54330cd-90dc-41f8-bcd5-22d87701d876"
}
        

Event Data Returned on Successful Login

Json example:

            {
   "command":"zignsec_postback",
   "errorcode":"",
   "error":"",
   "token":"1decb781-37db-4477-92f8-223586dd4f0f"
}