PostMessage issues in SL360
Dec 07, 2017
Hi!
I have to link an embedded interactive video to SL. For this I want to use the PostMessage() method from iframe to parent. With the little experience I have in Javascript I first had to find out the basics. Now I'm able to get the connection working in html with two different domains, send a message and check if the condition of the message is right before executing anything.
For this I used the following javascript code.
//script used in the body of the iframe:
<script>
window.onload = function(e){
parent.postMessage('test', '*http://www.url.com');
};
</script>
// *i've changed the url for this message
//script used in the body of the HTML parent:
<script>
window.addEventListener('message',function(e){
if(e.data == 'test'){
alert('true');
console.log('message received...');
console.log(e);
}
});
</script>
//script used in Storyline onClick Execute Javascript trigger:
window.addEventListener('message',function(e){
if(e.data == 'test'){
alert('true');
console.log('message received...');
console.log(e);
}
});
In SL I've inserted the same iframe. I've created a simple button to trigger the script. I've published to web and uploaded it to the same domain as the parent HTML I mentioned before. Unfortunately it doesn't work. Does anyone know what I'm doing wrong? Can anyone help me?
//I'm getting this message in the developer console while testing in Chrome
app.min.js:32 Uncaught TypeError: Cannot read property 'request' of undefined
at t.onVolumeChanged (app.min.js:32)
at c (app.min.js:11)
at Object.trigger (app.min.js:11)
at t.onVisibilityHidden (app.min.js:47)
at c (app.min.js:11)
at Object.trigger (app.min.js:11)
at HTMLDocument.<anonymous> (app.min.js:47)
1 Reply
Hello,
I have attached a couple of files for you to take a look at.
On timeline start there is a javascript function that listens for incoming messages. It will alert true if the message received is equal to: test
The webobject points to an html file on my server. I named it child. It has a javascript window.onload function that calls parent.postMessage.
This discussion is closed. You can start a new discussion or contact Articulate Support.