MaterialXLab API  0.0.1
APIs For MaterialXLab Libraries
Loading...
Searching...
No Matches
JsFrameMessenger.js
Go to the documentation of this file.
6 constructor(parent, options = {}) {
7 this.parent = parent.contentWindow
8 this.options = options;
9 }
10
15 post(message) {
16
17 const targetOrigin = this.options.targetOrigin || '*';
18
19 console.log('> Post message to target:', targetOrigin, message);
20 this.parent.postMessage(message, targetOrigin);
21 }
22}
23
24// Example usage:
25/* const messenger = new IframeMessenger('https://example.github.io/iframepage.html', {
26 id: 'myIframe',
27 targetOrigin: 'https://example.github.io'
28});
29messenger.create();
30messenger.show();
31// To send input data
32messenger.post(JSON.stringify({ type: "document", value: "material doc" }));
33// To set viewerOnly mode
34messenger.post(JSON.stringify({ type: "viewerOnly", value: true }));
35*/
post(message)
Posts a message to the iframe.
constructor(parent, options={})