Page 1 of 1

Get source from an Iframe

Posted: Sat Jun 02, 2018 1:44 pm
by thefunkyjoint
Hi,

When i use the RetrieveHtml method, it won't get the source of an Iframe of the page. How can i get the source of an specific Iframe inside the page ?

Thanks

Re: Get source from an Iframe

Posted: Sat Jun 02, 2018 2:07 pm
by salvadordf
Hi,

There are 3 overloaded versions of TChromium.RetrieveHTML :
  • TChromium.RetrieveHTML(const aFrameName : ustring = '');
  • TChromium.RetrieveHTML(const aFrame : ICefFrame);
  • TChromium.RetrieveHTML(const aFrameIdentifier : int64);
if you use TChromium.RetrieveHTML without parameters you will get the HTML code from the main frame.

You can call TChromium.GetFrameNames or TChromium.GetFrameIdentifiers to get the frame names or identifiers and then call TChromium.RetrieveHTML with one of those names or identifiers to get the HTML code from that frame.

Re: Get source from an Iframe

Posted: Sat Jun 02, 2018 4:19 pm
by thefunkyjoint
Thank you very much for answering Salvador !

Any examples how to use GetFrameNames ? It has a TStrings parameter, but this is an abstract class...

Re: Get source from an Iframe

Posted: Sat Jun 02, 2018 4:45 pm
by salvadordf
Create a TStringList and use it as the aFrameNames parameter. If necessary cast it as TStrings :

Code: Select all

Chromium1.GetFrameNames(TStrings(MyStringList));

Re: Get source from an Iframe

Posted: Sat Jun 02, 2018 5:19 pm
by thefunkyjoint
Thank you, this worked. Is there a way to get the frame html source by its id in DOM ?

Re: Get source from an Iframe

Posted: Sat Jun 02, 2018 6:21 pm
by salvadordf
As far as I know, you can only search by the DOM name. The "identifiers" have nothing to do with the "id" DOM attribute.

Perhaps you can set the focus on some element inside the desired frame and call TChromium.Browser.FocusedFrame

Re: Get source from an Iframe

Posted: Sun Jun 03, 2018 10:53 am
by thefunkyjoint
Ok, no problem, the other method worked ! Thanks ! :D