Webbrowser operation notes

Source: Internet
Author: User
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> <Br/> If the webpage contains such a statement: <br/> </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> <Br/> assume there is a script like this: <br/> </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> <Br/> If the webpage contains the following content: <br/> <span id = "span1"> This is the content in the span1 tag </span> <br/> </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...

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.