Forum Discussion
WebObject and Storyline Variable
It seems something has changed, because my files that used to work (just above) are no longer working. I get the sad web page icon. It's the same with Jean-Guy's file that was working above. Does anyone know if there's a workaround, or what we can change to get web objects to work in Storyline again?
If you delete and add a new webobject with the same address it will work again. The new storyline webobject needs to be replaced. But, Chrome security updates have gimped much of the communication. I have switched to postMessage for SL to WebObject and vice versa communication.
The iframe is still being assigned to the iFrameId, but the variable delivery will no longer work.
I switched to postMessage last year to deliver variables between webobject and storyline.
You can add a javascript trigger to send a post message with the variables. Pretty sure this needs to be added on the same layer as the webObject.
/////////////////////// In SL ///////////////////////////////
var player = GetPlayer();
const iframe = document.querySelector('iframe[data-dv_ref="iframe"]');
const var1 = player.GetVar("var1");
// Function to send message to the iframe
function sendVar(data) {
iframe.contentWindow.postMessage(data, '*'); // '*' for all origins (adjust if needed)
console.log("Message sent To Iframe");
}
const eventData = { dataName: var1};//dataName can be anything, just make sure it matches the listener you have in the webobject.
console.log("sending custom event to iframe");
sendVar(eventData);
/////////////////// In SL end ///////////////////////////////////
/////////////////// In web object ///////////////////////////////
// add this to your webobject in a script
window.addEventListener('message', function(event) {
if (event.data.dataName) {
const var1 = event.data.dataName; //this is the variable to that was sent.
console.log("Received Var from parent:", var1 );
}
});
/////////////////// In web object end ////////////////////////
I hope this helps/works for you.