使用Tidhttp与Twebbrowser

meg*_*r0n 5 delphi internet-explorer activex indy twebbrowser

我正在使用tidhttp控件来加速Twebbrowser中的网页加载.导航到网址很慢,这就是为什么我不使用它(WebBrowser1.Navigate('some_url_here')).我是这样做的:

procedure TForm1.Button2Click(Sender: TObject);
  procedure LoadHtmlIntoBrowser(var WB: TweBbrowser; const HTMLString: string);
  var
    v: OleVariant;
    HTMLDocument: IHTMLDocument2;
  begin
    WB.Navigate('about:blank');
    while WB.ReadyState < READYSTATE_INTERACTIVE do
      forms.Application.ProcessMessages;

    if Assigned(WB.Document) then
    begin
      HTMLDocument := WB.Document as IHTMLDocument2;
      v := VarArrayCreate([0, 0], varVariant);
      v[0] := HTMLString;
      HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
      HTMLDocument.Close;
    end;
    forms.Application.ProcessMessages;
  end;

var
  str:string;
begin
  str:=idhttp1.Get('http://localhost/myhome.html');
  LoadHtmlIntoBrowser(WebBrowser1,str);
end;
Run Code Online (Sandbox Code Playgroud)

我使用它idHTTP来将html内容转换为字符串,然后将该字符串直接写入Webbrowser.我有一个本地Web服务器设置(XAMPP).我遇到的问题是,在将html内容写入浏览器并点击显示的链接之后,它没有任何地方,即它显示一个大多数空白页面,顶部有"twopage.html".当我右键单击并"查看源代码"时,我得到的"<html>twopage.html</html>"是奇怪的,而不是页面的实际html.

"myhome.html"文件包含

<html>
  <head></head>
  <body><h1>My home</h1><a href="twopage.html"></a></body>
</html>
Run Code Online (Sandbox Code Playgroud)

The other webpage, "twopage.html" contains

<html>
  <head></head>
  <body><h1>Another Webpage</h1></body>
</html>
Run Code Online (Sandbox Code Playgroud)

Rem*_*eau 7

在将<base>标记加载到Web浏览器之前,您需要在HTML中插入标记,以便在解析相对URL时它具有可用的基本URL.