Get iFrame title in dynamic list

Hey guys,

I’m stuck with trying to get the title of an iFrame. My iFrames are placed inside a block, which itself is in a cell->row->data container. The purpose of the parent block is to set an anchor, which is not possible with the iframe itself. Thought this enables me to use document.getElementById("block-anchor").firstChild.contentDocument.title to retrieve the title of the iFrame. While I’m able to select the block element iself, selecting the iFrame with firstChild (or lastChild or children[0]) fails and therefore the following selection of contentDocument.title throws an error.

My next approach was to use the iFrame component itself when mounted (similar to this cookbook recipe here) and select the title from there.
Screenshot 2023-04-14 165546
Screenshot 2023-04-14 165603

However it seams like I can’t target the properties.
Screenshot 2023-04-14 165626

I read in another post that direct DOM manipulations are not desirable. I’m not sure if this applies to the above mentioned problem too.

Any help would be appreciated.

Best,
Anton

Hello @Anton_Henkelmann

You could try the following logic

image

With the next code:

console.log(iframeComponent.el.firstChild.contentWindow.document.title)

Where iframeComponent is an argument of custom code

Don’t forget: iframe loaded asynchronously, so you should wait until it loaded before getting the title.

Regards, Dima.

Hey @Dima

Your hint regarding the asynchronous loading of iFrames brought me on the right track. Thanks for the fast help :+1: