i am trying to get the product name and post it inside my html but i have this error: Uncaught TypeError: Cannot read property 'postMessage' of undefined.
i used debugger and the productName is sent but as the code continue to run something is wix code breaks and i have that error, can anyone please help
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady( async function () {
let product = await $w("#productPage1").getProduct();
if (product) {
let productName = product.name;
$w("#html1").postMessage(productName);
}
} );
You can see more about working with the html element here.
https://support.wix.com/en/article/corvid-working-with-the-html-element
https://www.wix.com/corvid/reference/$w.HtmlComponent.html
Also, take a look at this example here.
https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site
Try it as the example shows first and see if it just runs with product.
import wixData from 'wix-data'; import wixWindow from 'wix-window'; let product; $w.onReady(async function () { product = await $w('#productPage1').getProduct();
Understanding the Code
Lines 1-2: Import the modules we need to work with Wix Data and Wix Window libraries.
Line 5: Define the global product variable.
Line 7: When the page loads, do the following:
Line 8: Using the getProduct function on the current product page, set the product variable to the currently displayed product.
I'm currently facing the same problem. Did you find a solution?