Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

How to enable editing of a document in TWebBrowser (in Delphi applications)

Title: How to enable editing of a document in TWebBrowser (in Delphi applications) If you need to enable a user to change the contents of a document (web page) displayed by the TWebBrowser component, use the following trick: ~~~~~~~~~~~~~~~~~~~~~~~~~ uses MSHTML; //Drop a TWebBrowser (name: WebBrowser1) on a form... procedure TForm1.FormCreate(Sender: TObject) ; begin WebBrowser1.Navigate('http://delphi.about.com') ; end; //this handles the OnNavigateComplete event of WebBrowser1 procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant) ; begin ((Sender as TWebBrowser).Document as IHTMLDocument2).designMode := 'on'; end; ~~~~~~~~~~~~~~~~~~~~~~~~~ Note: The IHTMLDocument2's designMode property is used to put WebBrowser into a mode where a user can edit the current document. While the browser is in design mode, objects enter a UI-activated state when the user presses ENTER or clicks an object that has focus, or when the user double-clicks the object. Once the editing is finished you should set designMode to 'no' - then you can save the changed document's HTML to a file. More TWebBrowser tips and tricks.