M
MyDelphiPower
Unregistered / Unconfirmed
GUEST, unregistred user!
有TWebBrowser打开一个网站后,先在TWebBrowser里插入一些HTML,但出现乱码,我现在的做法是:先获取网页的内容再在再接上我要加上的内容,代码如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
//打开GOOGLE
WebBrowser1.Navigate('www.google.com');
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
v: Variant;
HTMLDocument: IHTMLDocument2;
str,strHtml:string;
all:IHTMLElementCollection;
item:OleVariant;
begin
HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
all:= HTMLDocument.all;
item:=all.item(0,varEmpty);
str:=item.outerhtml;
v := VarArrayCreate([0, 0], varVariant);
v[0] := 新增加的内容'' + str;
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
另外,我发现,就算不接上新增加的内容,获取网页代码后又直接写回TWebBrowser也会出现乱码
procedure TForm1.Button1Click(Sender: TObject);
begin
//打开GOOGLE
WebBrowser1.Navigate('www.google.com');
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
v: Variant;
HTMLDocument: IHTMLDocument2;
str,strHtml:string;
all:IHTMLElementCollection;
item:OleVariant;
begin
HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
all:= HTMLDocument.all;
item:=all.item(0,varEmpty);
str:=item.outerhtml;
v := VarArrayCreate([0, 0], varVariant);
v[0] := 新增加的内容'' + str;
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
另外,我发现,就算不接上新增加的内容,获取网页代码后又直接写回TWebBrowser也会出现乱码