How to use Delphi WebBrowser (v)-difficulties and explanations

Source: Internet
Author: User
Tags ole

http://blog.csdn.net/xtfnpgy/article/details/15809635

Page code: <select id=fy Onchange=touchrefresh (1) name=fy> <option selected value=15> per page 15 pen </OPTION> <option value=30> per page 30 pen </OPTION> <option value=60> per page 60 pen </OPTION></SELECT>

1.webbrowser execution of JS functions in Web pages

If you want to perform the Touchrefresh (1) function:

Webbrowser1.oleobject.document.parentwindow.ExecScript (' Touchrefresh (1) ', ' Javascript ');

WebBrowser executes its own JS function:
Wb1. OleObject.document.parentwindow.ExecScript (' Alert (' Custom function '); ', ' JavaScript ');

Method 2:

Wb1. Navigate (' Javascript:alert (' executed successfully! ');

2.webbrowser Select drop-down list

Var

Ole:olevariant

Begin

OLE: = Webbrowser1.oleobject.document.GetElementByID (' fy ');

Ole.value: = 60; Drop-down box with value, check box and multi box with checked:= ' true '

Ole.onchange; Calling the onchange Event

End

3.webbrowser submitted according to form (no ID and name for submit button)

Page code:

<form id=loginform onsubmit= "return Validate_form ()" Method=post action=/pass/serviceloginauth2><input id= Passtoken Type=hidden name=passtoken>

<input style= "Display:none" Id=user class= "Input_kuang Item Errortip" name=user>

<input style= "Display:none" id=pwd class= "Input_kuang item Errortip" value= "" Type=password name=pwd>

<div class= "Sub_login flt_l" ><input class= "NO_BG" value= log in Type=submit></div>

Submission Method:

WebBrowser1. OleObject.document.forms.item (' LoginForm '). Submit;

4.webbrowser Remove scroll bar

In the Download event:
Webbrowser1.oleobject.Document.body.Scroll: = ' no ';
Webbrowser1.oleobject.Document.documentElement.style.overflow: = ' hidden ';

WebBrowser Control scroll bar scrolling:
WebBrowser1. OleObject.document.parentwindow.scrollby (0,100);//The first parameter is horizontal, the second vertical Scrollby the number of scrolls
WebBrowser1. OleObject.document.parentwindow.scrollto (0,1000);//Scrollto scroll to a location

5.webbrowser Masking right mouse button TEMBEDDEDWB setting disabledpopupmenuitems property

WebBrowser1. Disabledpopupmenuitems: = [Rcmdefault,rcmimage,rcmcontrol,rcmtable,rcmseltext,rcmanchor,rcmunknown,rcmimageart, Rcmimgdynsrc,rcmdebug,rcmall]

6.webbrowser Masking web Images TEMBEDDEDWB setting downloadimages properties

WebBrowser1. DownloadOptions: = [];

7.webbrowser get elements by attributes of elements

function Getdoclinkbyhref (doc:ihtmldocument2;str_url:string): ihtmlanchorelement;

Var
I:integer;
Label_idispatch:idispatch;
Label_element:ihtmlanchorelement; Reference mshtml
Begin
Result: = nil;

Doc: = Webbrowser1.document as Ihtmldocument2;
If not Assigned (DOC) Then
Exit;
For i:=0 to Doc.links.length-1 do
Begin
Label_idispatch: = Doc.links.item (i,0);
Label_element: = Doc.links.item (i,0) as ihtmlanchorelement;
if (Ansipos (Str_url), (Doc.links.item (i,0) as IHTMLElement). getattribute (' tag ', 0))
Then
Begin
Result: = label_element;
break;
End
End
End

8.webbrowser TEMBEDEDWB Shielding the pop-up window and capturing the popup information//processing in the TEMBEDEDWB onshowmessage event

Procedure Tform1.wb1navigatecomplete2 (Sender:tobject;
Const Pdisp:idispatch; var url:olevariant);
Var
str_url:string;
Begin
Wb1.OleObject.document.parentWindow.execScript (' window.alert=null; ', ' JavaScript ');
Wb1.OleObject.document.parentWindow.execScript (' window.open=null; ', ' JavaScript ');
Wb1.OleObject.document.parentWindow.execScript (' window.close=null; ', ' JavaScript ');
Wb1.OleObject.document.parentWindow.execScript (' window.showmodaldialog=null; ', ' JavaScript ');
Wb1.OleObject.document.parentwindow.execscript (' function confirm () {return true;} ', ' Javascript ');
End

function Tform1.webbrowser1showmessage (sender:tobject; hwnd:cardinal; Lpstrtext, Lpstrcaption:pwidechar; Dwtype:integer; Lpstrhelpfile:pwidechar;

Dwhelpcontext:integer; var plresult:integer): HRESULT;
Begin
Plresult: = IDOK; Shielding Alert\open\close and other pop-up windows
Result: = S_OK; Block the Confirm confirmation box and click Confirm
Mmo1.  Lines.add (Lpstrtext); Lpstrtext is the captured pop-up window content
End

Shield WebBrowser procedure Closesound;var hwinmm:cardinal in the page;  Pwaveoutwrite:pointer; lp:cardinal;  Begin HWINMM: = LoadLibrary (' Winmm.dll ');  If hwinmm > 0 then pwaveoutwrite: = GetProcAddress (hwinmm, ' waveoutopen ');    If Pwaveoutwrite <> nil then begin VirtualProtect (Pwaveoutwrite, 3, PAGE_EXECUTE_READWRITE, LP);  Move (# $C 2#$18#$00, pwaveoutwrite^, 3); End;end;

Force Webbroser to use IE8 kernel SetWBCoreIE8 (8000);

Procedure SetWBCoreIE8 (I_value:integer);

Var
str_exename:string;
Reg:tregistry;
Begin
Try
Str_exename: = Rightfromstr (application.exename, ' \ ', False);
Reg: = Tregistry.create;
Reg. Rootkey: = HKEY_LOCAL_MACHINE;
If Reg. Openkey (' Software\Microsoft\Internet Explorer\Main\FeatureControl ', False) then
Begin
If not Reg. Keyexists (' feature_browser_emulation ') then
Reg. CreateKey (' feature_browser_emulation ');
End
Reg. Closekey;
If Reg. Openkey (' Software\Microsoft\Internet explorer\main\featurecontrol\feature_browser_emulation ', False) then
Begin
Reg. Writeinteger (Str_exename,i_value);
If not Reg. Valueexists (Str_exename) Then
Begin
Reg. Writeinteger (Str_exename,i_value);
End
End
Reg. Closekey;
Reg. Free;
Except
End
End

Finally, give a link to the previously collected articles about WB:

Delphi Webbrowser

Delphi Analog Auto Login web WebBrowser
Delphi WebBrowser Find Object Implementation Auto Login _
Delphi WebBrowser and Delphi Interactive!!!
WebBrowser components and the use of Mshtml in Delphi Delphi
Delphi in Webbrowser-max Woods-Blog Park
The use of WebBrowser components and mshtml in Delphi
WebBrowser easy to automate form filling
WebBrowser operation-in case-blog Park
How to use WebBrowser in Delphi-Wystec's diary-NetEase Blog
Delphi WebBrowser Traversing page elements
Delphi7 WebBrowser making Web Form auto-Submitter step-up Analysis (1)-Zhong Xing 9th-Blog Park
How to operate WebBrowser control in multi-threaded environment in Delphi
Delphi uses Webservise to login Baidu
VB WebBrowser the way to add code to the page _ Baidu know
Close the WebBrowser pop-up box (dialog box
Delphi WebBrowser (or Embeddedwebbrowser) control opens some Web site "Invalid floating point operation" Exception resolution-XUXN-Blog Park
Property method event for WebBrowser Document object in Delphi _ Hard and Soft blog _ Sina Blog
Delphi gets a handle and sends a message
Delphi WebBrowser Get IFRAME page content
Twebbrowser How to write multithreading? -Delphi _ Network Communication _ Distributed development
"Discover" how to block out the sound of WebBrowser when refreshing a webpage-boringlamb-Blog Park
Re-expansion of the Extendedwebbrowser (continued) _ Breathing space _ Baidu Space
Receive IWEBBROWSER2 automation events _my_ Baidu Space
Delphi WebBrowser Development Browser _sap learn _ABAP_ Baidu space
"Go" WebBrowser cookie operation (relationship with Cookiecontainer) _ Quiyu Studio _ Baidu Space
WebBrowser Transformation of Blue bird-delphi, alteration method of Alter and other dialog box in webpage (reprint)
How do I find WebBrowser open the interface of Flash in Web page? Can I use this interface to control flash playback? _VC Advanced Research-Block group
WebBrowser Gets the Web page flash handle to simulate the click Problem-. NET Technology _ C #
VB how to send the left click event to flash in WebBrowser1-VB _ Network programming
Using WebBrowser to implement HTML interface
Extended WebBrowser Control dragwebbrowser flashgamewebbrowser_c# View _cs Programmer's Window
WebBrowser Set agent (100 points)-Delphi _ Network Communication _ Distributed development
Mask the sound from the WebBrowser page-jxgxy-Blog Park
Can I set up a proxy server that is not used for multiple WebBrowser in the same program?
Local: Dual-line, dual-IP, dual-NIC Setup Online _ Who am I? -andy gu_ Baidu Space
Web Page dialog box using EMBEDDEDWB to mask specified content in Delphi-Patrick Pullman-Blog Park
Web Browser control–specifying The IE version-rick Strahl ' s web Log
WebBrowser the relationship with IE, how to set WebBrowser work in IE9 mode? -Bobliu-Blog Park
WebBrowser, cannot free memory? -CSDN Forum-Csdn.net
Why the browser uses a multi-process architecture. -Ithzhang-Blog channel-csdn.net
Windows messages-In case-blog Park
"WebBrowser" multi-process programming (i)-Dick_china's Column-Blog channel-csdn.net
How to set the rendering mode of IE8 WebBrowser control (MSHTML)-IE browser development!!
Replace Webbrowser-bach with Tchromium-Blog Park
WebBrowser Control Select drop-down list _ 风月无边 _ Baidu Space
All properties in the HTML drop-down list box-resolved-search and ask
Delphi to write a browser to modify cookies
TEMBEDDEDWB Component-embeddedwb-bsalsa Forum
WebBrowser get Web page Flash handle simulation Click Problem-CSDN Forum-Csdn.net

Support the original, reproduced please indicate the source!

How to use Delphi WebBrowser (v)-difficulties and explanations

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.