Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The JS code is evaluated on client by calling window.eval() function before run and an exception will be thrown if it is not valid what will cause a client disconnect.

Post a message

...

You can use this mechanism and run JavaScript code that will post a message from iframe to its parent. There are two ways to send a message:

Via ‘xepstm_to_p’ event

Create a xepstm_to_p event with two members _m for message name and _mc for message content.

...

from Kudo Editor iframe to Partner Web Application

Using our SDK

Our SDK provides two convenient C++ functions for the communication from Kudo Editor loaded in an iframe to a Partner Web Application referred as parent in the SDK, see API Reference.

Code Block
void XeIntegration::postStringToParent( std::string js = "{"
        "var event = document.createEvent('Event');"
        "event.initEvent('xepstm_to_p', true, true);"
        "event._m = messageName;"
        "event._mc = messageContent;"
        "window.dispatchEvent(event);"
        "}";
    Wt::WApplication::instance()->doJavaScript(js);
}

messageName and messageContent are arbitrary strings.

This will send a JSON message like this to parent frame:

Code Block
{
    messageName: messageName,
    message: messageContent
}

Using postMessage

...

message );
void XeIntegration::postJSONMessageToParent( std::string messageName, std::string messageContent );

We also provide a ready-to-go example application “CrossOriginIntegration”, see samples. This example is a custom module that can be loaded by Kudo Server. 

Using postMessage

In addition to the helper functions, the Web API function “Window.postMessage()” can be used directly in your module. For that, JavaScript code executing this function must be transferred from Kudo Server to the client browser. 

Sending a simple string from the Kudo Server to its iframe and from there to the parent (your web application) looks like this:

Code Block
XeUpdateLock lock;
if (lock)
{
    std    std::string js = "if (window.parent) {"
                                                  "window.parent.postMessage("my message", '*');"
                                          "}";
    Wt    Wt::WApplication::instance()->doJavaScript(js);
}