Hi!
I am trying to take a specific content (the content is the "linkurl" column, as you can see at the picture below) from the database and to put it in an HTML component, but I don't know what is the right code to do this (to take one of the "embed url" and to put it in the HTML component).
![](https://static.wixstatic.com/media/a27d24_ba68a45a864e481287537dada527410c~mv2.png/v1/fill/w_49,h_16,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_ba68a45a864e481287537dada527410c~mv2.png)
The linkurl column is set to text (cause it's an embed URL code).
I tried this but obviously, it won't work cause it is not a URL link.
$w.onReady( () => {
$w("#dynamicDataset").onReady( () => {
let item = $w("#dynamicDataset").getCurrentItem();
let url = item.linkurl;
$w("#html1").src = url;
} );
} );
Now I'm trying to use the postMessage, but I'm stuck here.
I don't understand how it works.
$w('#html1').postMessage($w('dynamicDataset').getCurrentItem().item.linkurl)
Please help me with this, thanks.
Me too, so I'm still trying to get this work!
Thanks for the help!
Take a look at my site so you'll see what I'm exactly trying to do (maybe it will give you another idea).
https://eitan462.wixsite.com/mysite
At the homepage you select "Gener" then you choose a "Picture" and then you should see the game page with the HTML component (MISSING...)= All this work with the dynamic database.
If no one has another idea, I'll do it manually.
I can't it working the way I want. The frame reloads, but gets errors on the code from the URL. It must be the way their code runs that prevents reloading the frame with a new data-game-name.
So, that means each game has a separate page. Not the end of the world - but I hate it when I can't figure things out.
Good luck,
Yisrael
Just set up a page for each game. Each page has an HtmlComponent with that game's HTML code as you have it in the database. Then, when a game is chosen, you can redirect to the proper page using the wix-location API, like this:
wixLocation.to("/zombie-choppa");
"If separate pages works for you that's the easiest." - How then?
"I'm trying to figure out how to "change" the code (game name) and then reload the frame because I'm curious - and stubborn." - I'm not sure if I understand you... How will it work?
If separate pages works for you that's the easiest. I'm trying to figure out how to "change" the code (game name) and then reload the frame because I'm curious - and stubborn.
There is no option to add something that will take the whole code and will put it in the HTML component? each page will have its own code Like this video:
Wix Code | How to Create a Dynamic Item Page and Index Page
Just to add to each page the "embed link" as well.
I have it working as well. What I can't figure out is how to change the game by sending another name in a message to the HtmlComponent. I can't get the iFrame to reload properly.
Strange it works on my website...
Here is a 3 examples that I'm using
<div class="miniclip-game-embed" data-game-name="zombie-choppa" data-theme="5" data-width="500" data-height="500" data-language="en"><script src="//static.miniclipcdn.com/js/game-embed.js"></script>
<div class="miniclip-game-embed" data-game-name="slime-pizza" data-theme="5" data-width="500" data-height="500" data-language="en"><script src="//static.miniclipcdn.com/js/game-embed.js"></script>
<div class="miniclip-game-embed" data-game-name="shootermata" data-theme="5" data-width="500" data-height="500" data-language="en"><script src="//static.miniclipcdn.com/js/game-embed.js"></script>
You can check their website for more info
https://www.miniclip.com/webmasters/en/
I see that one of the names is zombie-choppa - please give me a couple more names. I want to try this out and I'll get back to you.
They are all the same except for the names, I changed it to 'x' value.
<div class="miniclip-game-embed" data-game-name="x" data-theme="5" data-width="500" data-height="500" data-language="en"><script src="//static.miniclipcdn.com/js/game-embed.js"></script>
Before I break my head on this, can you show me a few more of your "embed URLs" HTML snippets? Do they all use the same URL? What is the difference between the different snippet?
It makes more sense to define ahead of time exactly what needs to be done. It'll then be much easier to come up with a solution.
Thanks for the replay...
In the picture above I have a list of embed URLs in database collection (for example:"<div class="miniclip-game-embed" data-game-name="zombie-choppa" data-theme="5" data-width="500" data-height="500" data-language="en"><script src="//static.miniclipcdn.com/js/game-embed.js"></script>
Each item will open a online game.
What I want is to create a dynamic option that will simply take the current list ^^^^ and will put it an HTML component. (it works if I do it manually).
I've already read everything about HTML and postMessage, and I'm struggling to find a solution.
I do not really understand how to build the correct code for this.
Hi,
Not exactly sure what you're trying to do, but let me just explain some points:
You can set an HtmlComponent's .src property to a siteURL:
$w("#html1").src = "https://www.wix.com";
You can send messages to the HtmlComponent, but you need an onmessage function in the embedded code to handle the message. See the article Working with the HTML Component in Wix Code for the details on communication between a page and an HtmlComponent. From the article, an example onmessage function:
<script type="text/javascript"> window.onmessage = (event) => { if (event.data) { let receivedData = event.data; } }; //... </script>
I hope this helps,
Yisrael