Save HTML content in WebBrowser

zhaozj2021-02-08  272

Save HTML content in WebBrowser

Use the IPersist interface to achieve HTML to file, the implementation under VB and Delphi is like this:

VB: DIM OPF as IPERSISTFILE SET OPF = WebBrowser1.document opf.save "ThefileNameHere.htm", False

Delphi: uses MSHTML, OleCtrls, SHDocVw, StdCtrls, ActiveX; function GetHTMLCode (WB: IWebbrowser2; ACode: TStrings): Boolean; var ps: IPersistStreamInit; s: string; ss: TStringStream; sa: IStream; begin ps: = WB. Document as ipersistStreaminit; s: = ''; ss: = tstringstream.create (s); try sa: = tstreamadapter.create (ss, soreference) as iStream; Result: = succeeded (Ps.Save (SA, BOOL (TRUE) ))); if result damtring; finally ss.free; end; end; as for the implementation method under VC, refer to Jiang Wei's article:

http://www.9cbs.net/develop/read_article.asp?id=18465

In addition, VB implementation requires reference OLE_LIB, this reference is downloaded at http://www.applevb.com/lib/tl_ole.zip

转载请注明原文地址:https://www.9cbs.com/read-1176.html

New Post(0)