5

Tidhttpコントロールを使用して、TwebbrowserでのWebページの読み込みを高速化しています。URLへの移動が遅いので、私はそれを使用しません(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;

を使用しidHTTPてhtmlコンテンツを文字列に変換し、その文字列をWebブラウザに直接書き込みます。ローカル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>

The other webpage, "twopage.html" contains

<html>
  <head></head>
  <body><h1>Another Webpage</h1></body>
</html>
4

1 に答える 1

7

タグをWebブラウザにロードする前にHTMLに挿入する必要があり<base>ます。これにより、相対URLを解決するときにベースURLを使用できるようになります。

于 2013-03-16T04:04:12.010 に答える