Iframe communication

This guide describes how to configure FontoXML to use iframe communication instead of our postMessage API.

FontoXML can be opened as an iframe. To allow communication between FontoXML and the host application. A common use case of this is offering a way to end the editing session from inside FontoXML by saving the opened documents and closing the editor or causing FontoXML to go full screen.

Communicating from the FontoXML iframe to its parent window

This use case describes direct interactions from the user that require direct feedback from the CMS. Examples interactions are: ‘Close FontoXML and return to the CMS’, ‘Save and close and return to the CMS’, ‘Toggle full screen’.

If the user clicks one of these buttons, FontoXML uses the HTML5 standard postMessage API to send the command to its parent window or frame. See postMessage API documentation for details.

The messageString is a serialized JSON representation of the message object.

The message object will always contain the following properties:

type: The message type, for example fontoxml-close or fontoxml-toggle-fullscreen.

scope: The scope object that was passed when FontoXML was opened, as specified in the CMS Connector contract.

metadata: An object that may contain command specific properties.

The JavaScript on the CMS’s page that created the iframe should listen to these messages using .addEventListener('message', callback) or .attachEvent('onmessage', callback)– depending on the browser – and act accordingly. The CMS is responsible for closing the iframe, resizing the iframe, releasing locks and/or cleaning up automatic saves if necessary.

Full screen

The sendToggleFullScreen method on IframeCommunicationManager uses the postMessage API to send a message to the parent window with the type set to fontoxml-toggle-fullscreen and the metadata containing a boolean property named isInFullScreenMode describing whether a full screen mode is requested. Call this method from an action to be able to use it from an operation.