Webbrowser1.gohome; // go to the default webbrowser1.refresh page of the browser; // refresh webbrowser1.goback; // return webbrowser1.goforward; // forward webbrowser1.navigate ('... '); // open the specified page webbrowser1.navigate ('about: blank'); // open an empty page
// Open the blank page and write... webbrowser1.navigate ('about:
// Read the variables in the webpage Script: Procedure tform1.button1click (Sender: tobject); var S: string; I: integer; begin S: = webbrowser1.oleobject.doc ument. script. STR; I: = webbrowser1.oleobject.doc ument. script. num; showmessage (s); // Hello showmessage (inttostr (I); // 99 // You can also read: S: = webbrowser1.oleobject.doc ument. parentwindow. STR; I: = webbrowser1.oleobject.doc ument. parentwindow. num; showmessage (s); // Hello showmessage (inttostr (I); // 99end;
<xmp> &lt;Br/&gt; If the webpage contains such a statement: &lt;br/&gt; </xmp>
// Call the Function Procedure tform1.button1click (Sender: tobject); begin webbrowser1.oleobject.doc ument. parentwindow. MB (); // html-js // to specify the script language, you need to: webbrowser1.oleobject.document.parentwindow.exe cscript ('mb () ', 'javascript'); // html-jsend;
<xmp> &lt;Br/&gt; assume there is a script like this: &lt;br/&gt; </xmp>
// Determine whether all webpages and internal framework webpages have been downloaded. Procedure tform1.webbrowser1documentcomplete (asender: tobject; const Pdisp: idispatch; var URL: olevariant); begin if webbrowser1.application = Pdisp then begin text: = 'webpage download complete! '; End;
// Change the background color or background image: webbrowser1.oleobject.doc ument. Body. bgcolor: = '{ff}'{webbrowser1.oleobject.doc ument. Body. Background: = '... image address ';
// Operation ID tag object: var S: string; begin S: = webbrowser1.oleobject.doc ument. getelementbyid ('span1 '). innertext; showmessage (s); // This is the content in the span1 tag // or: S: = webbrowser1.oleobject.doc ument. parentwindow. span1.innertext; showmessage (s); // This is the content in the span1 tag // hide it: webbrowser1.oleobject.doc ument. parentwindow. span1.style. display: = 'none'; end;
<xmp> &lt;Br/&gt; If the webpage contains the following content: &lt;br/&gt; &lt;span id = &quot;span1&quot;&gt; This is the content in the span1 tag &lt;/span&gt; &lt;br/&gt; </xmp>
// obtain the Source Code var S: string; begin S: = webbrowser1.oleobject.doc ument. body. innerhtml; // all Code S: = webbrowser1.oleobject.doc ument. body. outerhtml; // All code in the body, including the body tag s: = webbrowser1.oleobject.document.doc umentelement. innerhtml; // all codes in HTML end; // obtain all source code uses ActiveX; var MS: tmemorystream; begin if not assigned (webbrowser1.document) Then exit; MS: = tmemorystream. create; (webbrowser1.document as ipersiststreaminit ). save (tstreamadapter. create (MS), true); Ms. position: = 0; memo1.lines. loadfromstream (MS, tencoding. utf8); // memo1.lines. loadfromstream (MS, tencoding. default); {gb2312 and other double bytes} ms. free; end;
// right-click the menu in webbrowser // Add applicationevents1 to specify its message event // shield the right-click menu procedure tform1.applicationevents1message (var msg: tagmsg; vaR handled: Boolean); begin with MSG do begin if not ischild (webbrowser1.handle, hwnd) Then exit; handled: = (Message = wm_rbuttondown) or (Message = wm_rbuttonup) or (Message = wm_contextmenu); end; // Replace the right-click menu procedure tform1.applicationevents1message (var msg: tagmsg; var handled: Boolean); var mpoint: tpoint; begin if ischild (webbrowser1.handle, MSG. hwnd) and (MSG. message = wm_rbuttondown) or (MSG. message = wm_rbuttonup) then begin getcursorpos (mpoint); // obtain the cursor position popupmenu1.popup (mpoint. x, mpoint. y); // The popupmenu1 menu handled: = true; end;
// Add begin webbrowser1.navigate ('about: blank ') and webbrowser1.oleobject to the new page. document. writeln ('OK'); end; // write from the stream: var MS: tmemorystream; begin MS: = tmemorystream. create; memo1.lines. savetostream (MS); Ms. position: = 0; (webbrowser1.document as ipersiststreaminit ). load (tstreamadapter. create (MS); Ms. free; end; // the following error occurs: Procedure tform1.webbrowser1navigatecomplete2 (asender: tobject; const Pdisp: idispatch; var URL: olevariant); begin webbrowser1.silent: = true; end; // disable the window procedure tform1.webbrowser1newwindow2 (asender: tobject; var ppdisp: idispatch; var cancel: wordbool); begin cancel: = true; end;
Simulate clicking the button on the webpage
Operation Link
Supports higher version IE:
<Meta http-equiv = "X-UA-compatible" content = "Ie = edge"/>
// To be continued...