I am using the tidhttp control to speed up the loading of a webpage in a Twebbrowser. Navigating to the url is slow so thats why I don't use it(WebBrowser1.Navigate('some_url_here')
). Here is how i do it:
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;
I use the idHTTP
to get the html content into a string then write that string directly to Webbrowser. I have a local webserver setup(XAMPP). The problem I having is that after the html content has been written to the browser and I click a link that is displayed, it goes no where i.e. it shows a mostly blank page with "twopage.html" at the top. When I right click and "view source" i get "<html>twopage.html</html>"
which is strange and not the actual html of the page.
The "myhome.html" file contains
<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>
http://somewhere
. I don't know if you can inform it what that "base url" is, but you for sure can change your "myhome.html" file to include absolute links, for example<a href="http://localhost/twopage.html">
, which I bet will work in your setup. On the other hand, I really don't see how this can improve the time to load the page in a significant way, and I'm not sure if it works with a complex page involving related resources, like css, images and the such – jachguatemaybe it's not even possible
without at least one real navigation to the desired location. – TLama<base>
tag into the HTML before loading it into thewebbrowser
, so that the webbrowser has a base url to resolve relative links with. – Remy Lebeau