@cdov21 Before we go any further, you don’t say where the error is showing up. What line of code? What do you mean by “my iframes are displaying [object Object]”? Perhaps the code in your iFrames is not browser compatible. Make sure that you are using a Supported Browser .
The onMessage() functions do not go inside the dataset onReady() . However, then you need to declare the variable item outside of the dataset onReady() , something like this:
let item;
$w("#myDataset").onReady( () => {
item = $w('#zipcodeset').getCurrentItem();
} );
Did you try getCurrentItem inside of each onMessage()? Like this:
$w("#c1").onMessage((event) => {
item = $w('#zipcodeset').getCurrentItem();
if (wixWindow.formFactor === "Mobile") {
$w("#c1").postMessage(item.chart1Mobile);
} else {
$w("#c1").postMessage(item.chart1);
}
});
This seems to be an issue with browser timing and compatibility, and it’s sometimes difficult to track down what’s happening. You can add console.log() statements at various points to inspect what’s happening and (maybe most importantly) when. For example, see if an item is being returned, like this:
item = $w('#zipcodeset').getCurrentItem();
console.log('current item', item);
You will see the contents of the current dataset item (or the dreaded undefined) displayed in the console.
Use console.log() statements at different points of your code to see what’s happening. You can display values of variables, or just display information such as “got a message from c1”. See Testing and Debugging Your Code for more information on finding problems.