I need help, I am trying to do this few days already.
I have also opened post about it here
I'm trying to load an Iframe from dynamic page to HTML component using postMessage.
Maksim gave me these 2 options:
At the first code, there is no error in the console but nothing happens.
$w.onReady(async () => {
// you can use async/await instead of promises
// don't forget to replace with your dataset id
const embedCode = await $w('#dataset1').getCurrentItem().linkurl;
$w('#html1').postMessage(embedCode);
})
The second option gives me a no function error.
$w.onReady(() => {
$w('#dataset1').getCurrentItem().then(currentItem => {
const embedCode = currentItem.linkurl
$w('#html1').postMessage(embedCode)
})
.catch(error => {
console.warn(error)
})
})
I do understand what you're trying to do...
"...it will load the right embed code for the game, from the dynamic database to an empty HTML component..." --- This cannot be done. There is no way to "fill" an empty HtmlComponent. You can set the website that will be displayed in the HtmlComponent by setting the .src property. For example (from the API docs):
$w("#myHtmlComponent").src = "https://en.wikipedia.org/wiki/HTTPS";
If the service provider can provide you with a URL (with no HTML), then you can change which site to display inside in the HtmlComponent by setting the .src property in code.
You can change the .src property, but you cannot fill in an empty HtmlComponent.
Hello Yisrael, trying for long to use the HTML code corresponding to the element in the database but from reading this tread should we conclude that it is not possible? Is only one absolute HTML code possible to use in an iframe in a dynamic page? The same for https URL addresses in embedding frames in a dynamic page?
You can use the src property of HtmlComponent. Something like this:
$w("#myHtmlComponent").src = "https://www.google.com/maps/d/embed?mid=1WgTq-HwP9M7KlH8RdJRCYuYOQCIlynLL";
i have the same problem im trying to display google maps https://www.google.com/maps/d/embed?mid=1WgTq-HwP9M7KlH8RdJRCYuYOQCIlynLL just a link is it possible to load a link from database ?
I think you didn't understand what I'm trying to do. You may be right, but I'll explain again.
let say someone is in the action category and pick a game.
A new page will open (item page) and it will load the right embed code for the game, from the dynamic database to an empty HTML component (except for the .onmessage)
If there is no way to do it, how do I send him from a dynamic category to manual page. (each page with another game)
You are trying to send new code to the HtmlComponent, but postMessage does not replace the code in the HtmlComponent. It only sends a message to the HtmlComponent that needs to be handled by an onmessage() function.
There is no need to change the code.
If someone chooses to play a game, it will take the right embedded code from the list in the database to the HTML component.
Thanks for helping me again.
Neither of these options changes the contents of the HtmlComponent. The PostMessage() function sends the HTML code from the database to the HtmlComponent as a message. The HtmlComponent needs an onmessage() function to received the message (the HTML code), but it can't change the embedded code in the HtmlComponent.