On my Dynamic Page I have a HTML Element the Code for this HTML Object in in a Dynamic Dataset.
The Fieldname in the Dataset is "htmlcode"
The ID of the HTML Element is "#html1"
The ID of the Dataset is "#dynamicDataset"
This is what I used on the Pagecode to send the Message
$w.onReady(() => {
$w('#dynamicDataset').getCurrentItem().then(currentItem => {
const embedCode = currentItem.htmlcode
$w('#html1').postMessage(embedCode)
})
.catch(error => {
console.warn(error)
})
})
This is what I used in the HTML Element to receive the Message
<script type="text/javascript">
window.onmessage = (event) => {
if (event.data) {
let receivedData = event.data;
}
};
</script>
But when I Test the Page I Get this Error:
TypeError: $w(...).getCurrentItem(...).then is not a function
Try this one...
$w.onReady(() => { $w('#dynamicDataset').onReady(async()=>{ let ITEM = await $w("#dynamicDataset").getCurrentItem(); let embedCode = ITEM.htmlcode; $w('#html1').postMessage(embedCode); }); });
<script type="text/javascript"> window.onmessage=(event)=>{ if(event.data){ let receivedData = event.data; console.log(receivedData) } }; </script>