PostMessage

PostMessage is the HTML5 Web Messaging protocol which allows exchanging messages in the browser between the iframe storage and ONLYOFFICE Docs. It allows the online office frame to communicate with its parent host page.

otherWindow.postMessage(msg, targetOrigin)

Parameters

msg

The message data.

Type: string or JSON object

msg.MessageId

The message name.

Type: string

Example: "App_LoadingStatus"

msg.SendTime

The time the message was sent, expressed as milliseconds since midnight 1 January 1970 UTC.

Type: integer

Example: 1329014075000

msg.Values

The message properties.

Type: JSON object

targetOrigin

The otherWindow origin that must be for the event to be dispatched. It will be set to the PostMessageOrigin property provided in CheckFileInfo.

*otherWindow is a reference to another window that msg will be posted to.

Type: string

Here you can find the messages that are available for ONLYOFFICE Docs to send to the host page. The process of receiving messages by the online office will be available later.

Available messages

App_LoadingStatus

This message is posted after the online office application frame was loaded. Until the host receives this message, it must assume that the online office frame cannot react to any incoming messages except Host_PostmessageReady.

Blur_Focus

This message is posted by the host to stop the online office application from aggressively grabbing focus. Hosts should send this message whenever the host application UI is drawn over the online office frame so that the online office application does not interfere with the host UI behavior. This message is used only for the edit modes. It does not affect view modes.

Edit_Notification

This message is posted when the user first makes an edit to a document, and every five minutes thereafter, if the user has made edits over the last five minutes. Hosts can use this message to gauge whether users are interacting with the online office. In co-authoring sessions, hosts cannot use the WOPI calls for this purpose.

File_Rename

This message is posted when the user renames the current file in the online office. The host can use this message to optionally update the UI, such as the page title.

Grab_Focus

This message is posted by the host to resume aggressively grabbing focus by the online office application. Hosts should send this message whenever the host application UI that's drawn over the online office frame is closing. This lets the online office application resume functioning. This message is used only for the edit modes. It does not affect view modes.

Host_PostmessageReady

This message is posted by the host when it finishes loading. Then the online office frame receives Host_PostmessageReady, finishes loading, and sends the App_LoadingStatus message to the host page. After that, all the other PostMessage messages become available.

UI_Close

This message is posted when the online office application is closing, either due to an error or a user action. To send this message, the ClosePostMessage property in the CheckFileInfo response from the host must be set to true. Otherwise, the online office will not send this message.

UI_Edit

This message is posted when the user activates the Edit UI in the online office. This UI is only visible when using the view action. To send this message, the EditModePostMessage property in the CheckFileInfo response from the host must be set to true. Otherwise, the online office will not send this message and will redirect the inner iframe to the edit action URL instead.

UI_FileVersions

This message is posted when the user activates the Previous Versions UI in the online office. The host should use this message to trigger any custom file version history UI. To send this message, the FileVersionPostMessage property in the CheckFileInfo response from the host must be set to true. Otherwise, the online office will not send this message.

UI_Sharing

This message is posted when the user activates the Share UI in the online office. The host should use this message to trigger any custom sharing UI. To send this message, the FileSharingPostMessage property in the CheckFileInfo response from the host must be set to true. Otherwise, the online office will not send this message.

Collabora specific

Action_InsertGraphic

This message is posted to download an image from the URL and insert it into the document.

UI_InsertGraphic

This message is posted to display a user interface element (for example, a dialog) allowing the user to pick an image from the integration. The integration is supposed to provide a temporary URL that may be downloaded once, and return it back via the Action_InsertGraphic message with Values set to the temporary URL.

Please note that the PostMessage messages have the higher priority than the CloseUrl, HostEditUrl, FileSharingUrl, FileVersionUrl properties provided in CheckFileInfo.

Get Help

  • If you have any questions about ONLYOFFICE Docs, try the FAQ section first.
  • You can request a feature or report a bug by posting an issue on GitHub.
  • You can also ask our developers on ONLYOFFICE forum (registration required).