Manually writing HTML in TWebBrowser

EDIT: Look at Jorn's approach.
I use the strategy suggested here: http://cc.embarcadero.com/Item/23992 to get my HTML in TWebBrowser, but I get a bunch of JavaScript errors when loading the page. If I click yes enough, I see the page without formatting, and I assume the page does nothing.

My theory is that since the links in HTML are relative, the browser cannot load any of them. I have a transition from passing the "about: blank" URL to the navigation function, to transfer the servers homepage - in the hope that some kind of internal mechanism will be able to generate full paths, but no luck.

Any of them was able to successfully write the HTML file for writing to TWebBrowser manually.

+3
source share
2 answers

Since HTML does not come from a direct URL, you need to include the tag <base href=...>in the HTML code itself so that relative links can be resolved correctly.

+7
source

I usually use this approach:

//OnFormCreate:
begin
  WebBrowser.Navigate('about:blank');
end;

//OnButtonClick:
var
  Doc: Variant;
begin
  Doc := WebBrowser.Document;
  Doc.Clear;
  Doc.Write(Memo.Text);
  Doc.Close;
end;

There are also some good examples at delphi.about.com,
and some more complicated examples at www.delphidabbler.com

+9
source

Source: https://habr.com/ru/post/1744411/


All Articles