首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

网页是gb2312编码,WebBrowser加载显示的时候出现乱码解决办法

2012-02-25 
网页是gb2312编码,WebBrowser加载显示的时候出现乱码Delphi(Pascal) codeprocedure TForm1.WBLoadHTML(Web

网页是gb2312编码,WebBrowser加载显示的时候出现乱码

Delphi(Pascal) code
procedure TForm1.WBLoadHTML(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;

代码如上,但就是在加载GB2312编码的网页时出现乱码,其它的都能正常显示的,我加了
(WebBrowser.Document as IHTMLDocument2).Set_CharSet('GB2312');
这句还是不行

[解决办法]

HTMLCode:='<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>'+HTMLCode;
[解决办法]
HTMLCode:='<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>'+HTMLCode;

热点排行