Change src inside an iframe html code dynamically (via cms)

Hi

I have a dynamic page with a database of 20 items. On the item pages I have an iframe that has the same code (a viewer for something) and i want to change a url inside this iframe.

I tried the following:

$w.onReady(function () {
    // Access the current item in the dataset
    const currentItem = $w('#dynamicDataset').getCurrentItem();

    // Check if currentItem is defined
    if (currentItem) {
                $w('#html1').src = currentItem.myURL; 
    }
});

but it is not working. It does not recognize the urls defined in my database.
What am I doing wrong?

$w.onReady fires when the page loads, that happens before the Dataset is done fetching its data.

Try:

$w('#dynamicDataset').onReady(() => {
    const currentItem = $w('#dynamicDataset').getCurrentItem()
    if (currentItem) $w('#html1').src = currentItem.myURL
})

Is myURL the actual field key? Or is it myUrl? Or something else?

Does each URL have https? iFrames cannot have http, only https url’s.

Yes, the my.URL is the field name in my database and it is set to URL and all links have https

Actually by now I would be happy if I could just set the src Url of the iframe, even without any other code.

I tried it with Rich Content, but there it seems to get the iframe scaled to fit.

Mhhh, I can’t get t working with this. The iframe does not load up.
undefined ’s server IP address could not be found.

I added your code ahead of the other one, but no avail.

The value is turning up undefined, this means that is not the correct field tag

Let’s log the data then, see what you get

$w('#dynamicDataset').onReady(() => {
    console.log($w('#dynamicDataset').getCurrentItem())
})

You can also see the field tag within the Database view, when editing its properties

The field name and field key are two different variables. The field key is case sensitive .

A screenshot of your database and the page code, etc would help us see what you are seeing.