I’m loading an analytics script at the foot of my wix site’s body element. It writes variables to the browser’s native window object. I want to copy that data to a hidden form element in a form that is rendered with a Wix HTML Element. Wix renders the HTML Element in an iframe that it hosts from a different hostname. So the browser’s same origin security policy won’t let me post messages to it with normal javascript.
I’ve noticed that I can write to the iframe with:
$w.onReady(function () {
var iframe = $w("#html1");
iframe.postMessage('hi');
});
I need to be able to do one of these three things:
- A way to write directly from my analytics script to the iframe with normal javascript.
- Read the browser’s native window object from the $w.onReady() context, so that I can relay that data to the iframe with the code snippet above.
- Somehow pass a message to the $w.onReady() context from the native browser javascript context, so that I can relay that message to the iframe with the code snippet above.