jimPC
November 25, 2021, 11:32am
1
I have no idea as to achieve this…I’m pretty sure I can’t interrogate the post message with a query manager in wappler.
What would be the easiest way to update an array in the parent page from an iframe event.
If you can a bit of pseudo code would really help…
Thanks
patrick
November 25, 2021, 11:51am
2
A window.postMessage()
will trigger a message event on that window, so you need to listen there for the message window.onMessage = function() {}
or window.addEventListener('message', function() {})
.
The window.postMessage() method safely enables
cross-origin communication between Window objects; e.g., between
a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
jimPC
November 25, 2021, 12:12pm
3
Hi Patrick,
Great thankyou…
how would I update the array ‘content’ with the function,
unsure how to use dmx with js
window.addEventListener(‘message’, function() {
content = message ???
}) .
I have previously instantiated the variable
patrick
November 25, 2021, 12:29pm
4
use dmx.parse('content.setValue("' + message + '")');
1 Like
bpj
November 25, 2021, 12:35pm
5
jimPC:
the array ‘content’
Be careful naming the array 'content'. If using NodeJS the area used to add content pages has an ID of content so you could easily end up with clashed ID. Even if you aren't using Node now, I'd recommend using something else in case you transfer this project to NodeJS in the future.
jimPC
November 25, 2021, 12:37pm
6
Thanks bpj for the great advice,
As it happens I am using node so I’m sure you have helped me avoid potential problems…
1 Like
jimPC
November 25, 2021, 1:53pm
7
This works except for the dmx part…Any ideas??
var eventMethod = window.addEventListener ? "addEventListener": "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ? "onmessage": "message";
eventer(messageEvent, function (e){
var message = e.data || e.message;
if(message === "myevent"){
alert(message);
dmx.parse('session_status.setValue("' + message + '")')
}
})
jimPC
November 25, 2021, 2:05pm
8
Ok sorted
I placed the variable session_status in the layout page not the page where the iFrame was located…