Webbrowser problem collection in Delphi

Source: Internet
Author: User

Webbrowser problem collection in Delphi
Obtain the ID: = form1.webbrowser1 in the <SCRIPT> var currid = 123 </SCRIPT> program of the variable value htm on the webpage. oleobject. document. script. currid is worth noting that the variable can be defined by JavaScript or VBScript. If this variable cannot be found in webbrowser1, the call will trigger an exception event, that is, the variable currid does not exist.
2. Execute the function TMP: = 'currid = getnextid (currid) '+ #13 #10;
Form1.webbrowser1.oleobject.document.parentwindow.exe cscript (TMP, 'javascript '); the method to call a function is the execScript interface. Similarly, if the function does not exist or a running error occurs, a script error exception is triggered.
3. Set the webpage background image webbrowser1.oleobject. Document. Body. Background: = 'HTTP: // seelearn.com/bg.gif' background color webbrowser1.oleobject. Document. Body. bgcolor: = '# eeeeeeee'
4. Call the known object SRC: = webbrowser1.oleobject. Document. getelementbyid ('img1'). SRC on the webpage. This method is actually getelementbyid in JavaScript.
5. Obtain all frames on the page using DHTML.
Frames: Invalid wb.oleobject.doc ument. frames;
For I: = 0 to frames. Length do
Memo1.lines.add(frames[ I }.doc ument. body. innerhtml); 6. after borderstyle = bsnone, webbrowser will be reinitialized. This is a very unexpected problem. Delphi has done a very good job in the control of window controls, and few such bugs are analyzed, in many cases, formstyle is changed. changing the parent from Panel1 to panel2. also causes webbrowser to restart.
Initialization.
7. write HTML code directly to webbrowser without navigate to the actual file var.
Strstream: tstringstream;
Setnotestr: string; begin setnotestr: = '<body bgcolor = 222222 align = center> <br> <p align = center> <font size = + 2 color = # ffffff> click blog http://seelearn.com </font> </ p> ';
Setnotestr: = setnotestr + '<br> <p align = center> <font size = + 2 color = # ffffff> click the button on the left to view the corresponding image </font> </P>';
Strstream: = tstringstream. Create (setnotestr );
Webbrowser1.navigate ('about: blank ');
Try
Strstream. Position: = 0;
(Webbrowser1.document as ipersiststreaminit). Load (tstreamadapter. Create (strstream ));
Finally
Strstream. Free;
End;
8. forward and backward. Refresh self. webbrowser1.goback self. webbrowser1.goforward self. webbrowser1.refresh
9. Capture the newwindow2 event, that is, the new window event procedure tform1.webbrowser1newwindow2 (Sender: tobject;
VaR ppdisp: idispatch; var cancel: wordbool );
VaR
Newwindow: tform2;
Begin
// Exit;
Newwindow: = tform2.create (NiL );
Newwindow. show;
Ppdisp: = newwindow. webbrowser1.defadisdispatch;
End; it is worth noting that this method cannot obtain the URL of the new window. The method to exit is to wait until the beforenavigate2 event is triggered in the new webbrowser to judge.
10. If an IFRAME exists in the webpage, determine whether the page has been downloaded. Procedure tform1.webbrowser1documentcomplete (Sender: tobject;
Const Pdisp: idispatch; var URL: olevariant );
Begin if webbrowser1.application = Pdisp then showmessage ('Download all completed on the page') end; Description: after each IFRAME download is completed, the documentcomplete event is triggered, therefore, a page may be triggered multiple times before the download is completed.

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.