# Sending post message to CODE

**URL:** <https://forum.collaboraonline.com/t/sending-post-message-to-code/372>\
**Category:** Installation & Configuration\
**Created:** [May 13, 2021, 10:02pm UTC](https://forum.collaboraonline.com/t/sending-post-message-to-code/372 "2021-05-13T22:02:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mshadi](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@mshadi](https://forum.collaboraonline.com/u/mshadi)\
**Post date:** [May 13, 2021, 10:02pm UTC](https://forum.collaboraonline.com/t/sending-post-message-to-code/372/1 "2021-05-13T22:02:01Z")

</div>

Greetings.

By recieving UI\_SaveAs post message in my wopi host, I send Action\_SaveAs post message, but nothing happens.

Whats wrong with following code?

```
if(clientmsg.MessageId === 'UI_SaveAs'){
        const msg={
                "MessageId":'Action_SaveAs',
                "SendTime":Date.now(),
                "Values": {
                    "Filename": 'testname.txt',
                    "Notify":true
                }
            }
        frameWin.postMessage(JSON.stringify(msg),'*');
    }
```

---

<div class="post-metadata">

**Author:** ![rsoika](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.collaboraonline.com/rsoika/32/138_2.png) [@rsoika](https://forum.collaboraonline.com/u/rsoika)\
**Post date:** [May 15, 2021, 6:28am UTC](https://forum.collaboraonline.com/t/sending-post-message-to-code/372/2 "2021-05-15T06:28:00Z")

</div>

Make sure that your have added an eventListener to receive messages from the Wopi Client:

` window.addEventListener("message", receiveMessage, false);`

And than you should react on the first message ‘App\_LoadingStatus’ and send a ‘Host\_PostmessageReady’ message back to the client:

```
			if (msg.MessageId == 'App_LoadingStatus') {
				if (msg.Values) {
					if (msg.Values.Status == 'Document_Loaded') {
						console.log('==== Document loaded ...init viewer...');
						var iframe = document.getElementById('wopi-iframe');
			                        iframe = iframe.contentWindow || (iframe.contentDocument.document || iframe.contentDocument);									                   
                                                 iframe.postMessage(JSON.stringify({ 'MessageId': 'Host_PostmessageReady' }), '*');

					}
				}
				
			}

```

Find more details [here](https://sdk.collaboraonline.com/docs/postmessage_api.html).

---

<div class="post-metadata">

**Author:** ![darshan](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.collaboraonline.com/darshan/32/2230_2.png) [@darshan](https://forum.collaboraonline.com/u/darshan)\
**Post date:** [July 18, 2024, 1:49pm UTC](https://forum.collaboraonline.com/t/sending-post-message-to-code/372/3 "2024-07-18T13:49:58Z")

</div>

Closed on July 18, 2024, 1:49pm UTC


