加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 使用Tidhttp和Twebbrowser

发布时间:2020-12-15 09:32:11 所属栏目:大数据 来源:网络整理
导读:我正在使用tidhttp控件来加速Twebbrowser中的网页加载.导航到网址很慢,这就是为什么我不使用它(WebBrowser1.Navigate(‘some_url_here’)).我是这样做的: procedure TForm1.Button2Click(Sender: TObject); procedure LoadHtmlIntoBrowser(var WB: TweBbrow
我正在使用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;

我使用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>

另一个网页,“twopage.html”包含

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

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读