Browser to text

I have a WebBrowserControl1 and load a remote URL. I need a way to move the html from the control to a string. Is this possible?

Thanks

How about this? The ElementID for the TWebBrowserControl must be set (I've set it to "WebBrowserControl1" here), and I think there might be a requirement that the contents of the iframe have to be from the same site as the page it is on, but not sure about that.

procedure TForm1.WebButton1Click(Sender: TObject);
var
  html: String;
begin
  asm
    html = document.getElementById("WebBrowserControl1").contentDocument.documentElement.outerHTML;
  end;
  console.log(html);
end;

Thank you for the info. I tried the code but all I get back is
html head head body body html

There is no content, is there another way to get all the html code?

Thanks

Is the iframe loading a URL that is from the same domain? I believe there is a restriction that prevents you from looking at the contents. This is so that you can't hide an iFrame that secretly loads up, say, Faceboook where you can then look at the visitors' posts and that kind of thing.

Andrew.

Yes, it is from the same domain. I have a button with the code you have shown above. I need to press the button twice to receive the contents of the file. Not sure why it is not showing it on a single press?

Hmm... Not sure? Are the contents loaded before you click the button, and does the ElementID correspond to the control? You should of course be able to see the HTML you're after in the browser devtools, and everything should be in place before you click the button. If so, then ???

I had to load the contents before clicking the button to work. Now it is working.

Thank You

You're most welcome! Happy to help.