Programming Delphi Use the TWebBrowser as an html editor in delphi

How to enable the twebbrowser to be editing?
Inface, twebbrowser has a design mode state. It could be set to allow the user to edit the content of a webpage. In delphi, this function is very easy to be called.

See an example.

Create a new object, drag a TWebBrowser onto the form, double click the form and add the following codes to its creat event.

uses MSHTML;
procedure TForm1.FormCreate(Sender: TObject) ;
  WebBrowser1.Navigate('') ;

In the webbrowser1's event, double click the onDocumentComplete event to add codes.
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
   const pDisp: IDispatch; var URL: OleVariant) ;
   ((Sender as TWebBrowser).Document as IHTMLDocument2).designMode := 'on';

Run the project, when the page loaded, move your mouse onto the webbrowser area and click, see what happen.

Notice that when finish the editing, the designMode should be set to 'no' for saving the document's change.

Use this function in c++builder, see How to make the TCppWebbrowser editable in c++ builder

Add comment

Security code

Programming - Delphi