top of page

Forum Posts

stephan.conaway
Nov 11, 2020
In Coding with Velo
To support integration with a non-Wix ticketing system via iframes, I need to move a unique product URL from the Wix page to the embedded HTML object and build an iframe call with the imported URL. So far getting the unique URL to the Wix page from the Wix content store works fine, posting the URL to the embedded HTML object works via $w(“#html3").postMessage(testurl); works fine. receiving the message with works also as below: <script type=“text/javascript> var urlPath; window.onmessage = (event) => { if (event.data) { let receivedData = event.data; urlPath = receivedData; //** urlPath contains the correct URL from the page } } </script> The URL is received and both event.data and receivedData are initialised with the URL. However I cannot now move the URL from the function to build the iframe call. I’ve tried declaring global variables and moving the URL from receivedData to the global variable urlPath, but no matter what I’ve tried all variables used inside the function, global or local, are undefined outside the script that contains the window.onmessage function. I’ve tried moving the document.write that outputs the iframe HTML from within the embedded HTML to be also inside the script that contains the on message function, but this fails. Building the iframe outside of the that script works well in test if urlPath is simply loaded with the correct URL. How do I move the value of a variable from within this messaging function inside of an embedded HTML element for use outside of the function but still within the same HTML element?
0
0
105

stephan.conaway

More actions
bottom of page