uses
ActiveX;
procedure WB_LoadHTML(WebBrowser: TWebBrowser; HTMLCode: string);
var
sl: TStringList;
ms: TMemoryStream;
begin
WebBrowser.Navigate('about:blank');
while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
Application.ProcessMessages;
if Assigned(WebBrowser.Document) then
begin
sl := TStringList.Create;
try
ms := TMemoryStream.Create;
try
sl.Text := HTMLCode;
sl.SaveToStream(ms);
ms.Seek(0, 0);
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
finally
ms.Free;
end;
finally
sl.Free;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WB_LoadHTML(WebBrowser1,'SwissDelphiCenter');
end;
****************************
将HTML代码直接加入到TWebbrowser组件中去
uses
ActiveX;
procedure WB_LoadHTML(WebBrowser: TWebBrowser; HTMLCode: string);
var
sl: TStringList;
ms: TMemoryStream;
begin
WebBrowser.Navigate('about:blank');
if Assigned(WebBrowser.Document) then
begin
sl := TStringList.Create;
try
ms := TMemoryStream.Create;
try
sl.Text := HTMLCode;
sl.SaveToStream(ms); 0D
ms.Seek(0, 0);
(WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
0A finally
ms.Free;
end;
finally
sl.Free;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WB_LoadHTML(WebBrowser1,' <html > <body bgcolor= "#0099FF " >SwissDelphiCenter </html >');
end;
=========================
下面是左轻候的一段代码
//实现内容
procedure Tform1.ShowHTML(src:string;iebrw:TEmbeddedWB;ID:integer);
var
vv: Variant;
HTMLDocument: IHTMLDocument2;
tmpStr,tmpfilepath:string;0D
begin
//直接写到浏览器里。
vv := VarArrayCreate([0,0],varVariant);
vv[0] := ' <base href= "'+LocalPath+' "/ >'+ src+ tmpStr;
try
ieBrw.Navigate('about:blank'); //这里必须要
HTMLDocument := iebrw.Document as IHTMLDocument2;
HTMLDocument.write(PSafeArray(TVarData(vv).VArray));
HTMLDocument.charset:3D 'gb2312';
HTMLDocument.close;
except
statusbar1.Panels[0].Text:='写浏览器出错';
end;
HtmlDocument:=nil;
end;
两者还有是有区别的。写完后,第一个方法不会改变当前页默认的路径,就是说她是直接改内容。
而第二个就不行了,她完成后,你就会发现网页的属性为 "about:blank "
我也说不太清楚。请自己认真体会啊