开发者

Manually Writing the HTML in TWebBrowser

EDIT: Look at Jorn's approach.

I am using the strategy suggested here: http://cc.embarcadero.com/Item/23992 to get my HTML in the TWebBrowser, but I get a bunch of JavaScript errors when the page loads. If I click yes enough times I can see a page with no formatting and I'm guessing the page does nothing.

My theory is that because the links in the HTML are relative, the browser can't load any of it. I have switch from pa开发者_开发知识库ssing the URL, 'about:blank' to the navigate function, to passing the servers home page - in the hopes that some internal mechanism will be able to generate full paths, but no luck.

Any one successfully been able to manually write HTML to the TWebBrowser.


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 complex examples at www.delphidabbler.com


Since the HTML is not coming from a live URL, you need to include a <base href=...> tag in the HTML itself so relative links can be resolved correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜