The webbrower information collected on the internet is of great reference.

Source: Internet
Author: User

The self-organized webbrower basically covers all the online materials and MSN.

Http://hi.baidu.com/lovemoe/creat/blog/

Method description
Goback is equivalent to IE's "back" button, so that you can return

Goforward is equivalent to IE's "Forward" button, allowing you to move forward
Gohome is equivalent to the "Homepage" button of IE and connects to the user's default homepage.
Gosearch is equivalent to IE's "Search" button and connects to the user's default search page
Navigate connects to the specified URL
Refresh refresh the current page
Refresh2 is the same as above, but the refresh level can be specified. The value of the specified refresh level comes from the refreshconstants enumeration table,
This table is defined in exdisp. H. Different values can be specified as follows:
Refresh_normal: Do not send HTTP Pragma: No-Cache hair to the server
Refresh_ifexpired can be refreshed only after the webpage expires.
Refresh_continue is only used internally. Do not use in msdn! Do not use
Refresh_completely sends requests containing the Pragma: No-Cache header to the server

The stop button is equivalent to the "stop" button of IE to stop loading the current page and its content.
Attribute description
Application if this object is valid, the application in charge of the webbrowser control is returned.ProgramImplementation Automation Object (idispatch ). If the automation object in the Host object is invalid, this program returns webbrowser
Control Automation Object
Parent returns the parent Automation Object of the webbrowser control, usually a container, such as a host or IE window.
Container returns the automated object of the webbrowser control container. This value is usually the same as the value returned by the parent property.
Document is the automation object returned for the active document. If HTML is currently being displayed in webbrowser
The document attribute provides access to the DHTML Object Model.
Toplevelcontainer returns a Boolean value indicating whether IE is the top-level container of the webbrowser control. True is returned.

Type returns the type of the object loaded by the webbrowser control. For example, if the file "cmd.doc" is returned
Back to Microsoft Word Document
Left returns or sets the distance between the left side of the webbrowser control window and the left side of the container window.
Top return or set the distance between the left side of the webbrowser control window and the top side of the container window
Width: returns or sets the width of the webbrowser window, in pixels.
Height: returns or sets the height of the webbrowser window, in pixels.
Locationname returns a string containing the name of the currently displayed resource in webbrowser.
A webpage is the title of a webpage. A file or folder is the name of a file or folder.
Locationurl returns the URL of the resource currently being displayed in webbrowser.
Busy returns a Boolean value, indicating whether the webbrowser is currently loading the URL. If true is returned
You can use the stop method to cancel the ongoing access operation.

Http://hi.baidu.com/lovemoe/creat/blog/

 

Document attributes

Returns a string containing the HTML document name.

Silent attributes

Do not display any type of dialog box.

Documenttext attributes

Obtains or sets the HTML content of the current webpage.

URL attributes

Obtain or set the URL of the current webpage. When this property is set, the control is located to a new URL.

Documentcompleted event

This occurs when the webpage is loaded.

Beforenavigate event

Before the launch of the pilot program. Generally, the complete URL string is obtained here.

Goback goforward Gohome Method

Go to previous pages, next pages, and home pages in history.

Refresh Method

Refresh current page

Navigate Method

Locate the specified URL. The syntax of the navigate method is:
[Flags,] [targetframename,] [postdata,] [headers]

URL parameters

Uniform Resource Locator is a quasi-URL string used for navigation. For example, it can translate "www. Microsoft. com" into "http://www.MicroSoft.Com ".

Webbrowser usage

Http://hi.baidu.com/lovemoe/creat/blog/

Reference Microsoft HTML Object Library and Microsoft Internet controls

'Get Document Object
Set wbd = webbrowser1.document

Get webpageSource code

Webbrowser1.document.body.createtextrange().html text

Simplest Login

Set wbd = webbrowser1.document
Wbd. Body. All ("name"). value = ""
Wbd. Body. All ("pass"). value = ""
Wbd. Forms (0). Submit

Call JavaScript with Parameters

Wbd.parentwindow.exe cscript "document. login. Submit ()", "JavaScript"

Alert dialog box for shielding web pages

Private sub webbrowser1_navigatecomplete2 (byval Pdisp as object, URL as variant)
Pdisp.document.parentwindow.exe cscript "window. Alert = NULL ;"
End sub

Traversal

For mindex = 0 to mdocument. Forms. Length-1 'output each form
Print mdocument. Forms (mindex). Name
Lstlinks. additem "output connection"
For mindexex = 0 to mdocument. Links. Length-1 'output connection
Lstlinks. additem mdocument. Links (mindexex)
Next
Lstlinks. additem "image address"
For mindexex = 0 to mdocument. Images. Length-1 'output image
Lstlinks. additem mdocument. Images (mindexex). SRC 'image address
Next
Next

Operations after data download

Private sub webbrowserappsdocumentcomplete (byval Pdisp as object, URL as variant)
If URL <> "http://www.baidu.com/" then exit sub
Do
If not webbrowser1.busy then exit do
Doevents
Loop

Obtain the browser information:

Private sub commandementclick ()
Webbrowser1.navigate "http://www.applevb.com"
End sub
Private sub command2_click ()
Dim owindow
Dim onav
Set owindow = webbrowser1.document. parentwindow
Set onav = owindow. Navigator
Debug. Print onav. useragent
Set owindow = nothing
Set onav = nothing
End sub
(Click command1 to browse the webpage and click command2 to output the browser information in the prompt window .)

The webbrowser message window is displayed.

Dim owindow
Set owindow = webbrowser1.document. parentwindow
Owindow. Confirm "ABCD"

 

Page scrolling:

Private sub command2_click ()
Webbrowser1.document. parentwindow. scrollby 0, 30
End sub
Private sub form_load ()
Webbrowser1.navigate "http://www.applevb.com"
End sub
(Click command2 to scroll down the current page by 30 pixels)

Determine whether the page can move forward and backward

Private sub commandementclick ()
Webbrowser1.goforward
End sub
Private sub command2_click ()
Webbrowser1.goback
End sub
Private sub form_load ()
Webbrowser1.navigate "http://www.applevb.com"
End sub
Private sub webbrowser1_commandstatechange (byval command as long, byval enable as Boolean)
If (command = csc_navigateback) then
Command2.enabled = Enable
End if
If (command = csc_navigateforward) then
Command1.enabled = Enable
End if
End sub

Several Methods for writing HTML content to webbrowser:

First, add
Webbrowser1.navigate "about: blank"
Make sure webbrowser1 is available
Method 1:

Dim s as string
Dim stream as istream
S = ""
S = S + ""
S = S + ""
S = S + "Hello World"
S = S + ""
S = S +"
Webbrowser1.document. Write s

Method 2:

Dim o
Set o = webbrowser1.document. selection. createRange
Debug. Print o
If (not o is nothing) then
O. pastehtml "Haha"
Set o = nothing
End if

Method 3:

'Insert text box
Dim o

Set o = webbrowser1.document. selection. createRange
O.exe ccommand "inserttextarea", false, "XXX"

 

How to Prevent the webpage from having a scroll bar:

Private sub mnuscroll1_click ()
@ # Note: The task can only run after the webpage is fully displayed.
Webbrowser1.document. Body. Scroll = "no" @ # do not display the scroll bar
End sub
Private sub mnuscroll2_click ()
@ # Note: The task can only run after the webpage is fully displayed.
Webbrowser1.document. Body. Scroll = "Auto" @ # How to display the scroll bar
End sub

How to obtain the HTML of the selected part of a webpage:

Private sub commandementclick ()
Dim objselection
Dim objtxtrange

Set objselection = webbrowser1.document. Selection
If not (objselection is nothing) then
Set objtxtrange = objselection. createRange
If not (objtxtrange is nothing) then
Debug. Print objtxtrange.html text

Set objtxtrange = nothing
End if
Set objselection = nothing
End if
End sub

Private sub form_load ()
Webbrowser1.navigate "http://www.applevb.com"
End sub

 

 

 

 

 

============================
Use the Navigator or navigator2 method of webbrowser to open and pass an ASP document
Parameters are included, but parameters cannot be obtained in the ASP document. Why?

VB source code:
Private sub cmdsubmit_click ()
Dim strurl as string, strformdata as string
Dim strdata as string
Strurl = trim $ (txturl. Text)
Strformdata = "name =" & trim $ (txtname. Text )&

"& Password =" & trim $ (txtpassword. Text)
Call wbtest. navigate2 (strurl, 64, "_ blank", strformdata,

"Hello ")
End sub

ASP source code:

<% @ Language = VBScript %>
<%
Dim strname
Dim strpassword
Strname = trim (request. Form ("name "))
Strpassword = trim (request. Form ("password "))
Response. Write (strname)
Response. Write (strpassword)
If strname = "kingzhang" and strpassword = "123456" then
Response. Write ("Login successful ")
Else
Response. Write ("illegal login user! ")
End if

%>

**************************************** *****************************

Option explicit

Private sub commandementclick ()
Dim szvalue as string
Webbrowser1.document. Body. innerhtml ="

Method = post action = http: // address/xxx. php>
"
Webbrowser1.document. Forms ("Post"). Submit
End sub

Private sub form_load ()
Webbrowser1.navigate2 "about: blank"
End sub
Top

**************************************** ****************************

The navigate or navigate2 method provided in the webbrwoser control provides the ability to transmit data.

The call method is webbrowser1.navigate2 (URL, [flags],

[Targetframename], [postdata], [headers])
The postdata parameter is a submission parameter string, for example, "name = aaa & Password = 123 ",

But the question is, why is this method not effective and the server cannot obtain data?
If this method is valid, you do not need to use an htmlCodeSimulate this call.

The following code can detect the post messages of the program.

Private sub webbrowsersponbeforenavigate2 (byval Pdisp as object, URL as variant, flags as variant, targetframename as variant, postdata as variant, headers as variant, cancel as Boolean)
Msgbox postdata
End sub

How can I use the webbrowser control to display. gif animations?

A certain degree of Web Page Knowledge (HTML, JavaScript, CSS)
Note:
No "scroll bar" or "right-click ie context menu", ". htm source file "...
I wrote one and it worked really well!

'Objects: form1, command1, commondialog1, webbrowser1
Option explicit
Private sub commandementclick ()
Commondialog1.showopen
If VBA. Len (VBA. Trim (commondialog1.filename)> 0 then
Dim P as stdole. stdpicture
Dim Spath as string
Spath = VBA. Trim (VBA. Trim (commondialog1.filename ))
Set P = VB. loadpicture (Spath)
Webbrowser1.width = P. Width * 16/26
Webbrowser1.height = P. Height * 16/26
'Webbrowser1.navigate "about: blank"
Webbrowser1.document. Open
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln "webbrowser1.document. writeln"
Webbrowser1.document. writeln "webbrowser1.document. writeln"
"
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
End if
End sub
Private sub form_load ()
Command1.caption = "& Open"
Webbrowser1.navigate "about: blank"
Webbrowser1.document. Open
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. writeln "webbrowser1.document. writeln ""
Webbrowser1.document. writeln ""
Webbrowser1.document. Close
End sub

Webbrowser control description
Method description
Goback is equivalent to IE's "back" button, so that you can return

Goforward is equivalent to IE's "Forward" button, allowing you to move forward
Gohome is equivalent to the "Homepage" button of IE and connects to the user's default homepage.
Gosearch is equivalent to IE's "Search" button and connects to the user's default search page
Navigate connects to the specified URL
Refresh refresh the current page
Refresh2 is the same as above, but the refresh level can be specified. The value of the specified refresh level comes from the refreshconstants enumeration table,
This table is defined in exdisp. H. Different values can be specified as follows:
Refresh_normal: Do not send HTTP Pragma: No-Cache hair to the server
Refresh_ifexpired can be refreshed only after the webpage expires.
Refresh_continue is only used internally. Do not use in msdn! Do not use
Refresh_completely sends requests containing the Pragma: No-Cache header to the server

The stop button is equivalent to the "stop" button of IE to stop loading the current page and its content.

Attribute description
If this object is valid, the application returns the Automatic Object (idispatch) implemented by the application in charge of the webbrowser control ). If the automation object in the Host object is invalid, this program returns webbrowser
Control Automation Object
Parent returns the parent Automation Object of the webbrowser control, usually a container, such as a host or IE window.
Container returns the automated object of the webbrowser control container. This value is usually the same as the value returned by the parent property.
Document is the automation object returned for the active document. If HTML is currently being displayed in webbrowser
The document attribute provides access to the DHTML Object Model.
Toplevelcontainer returns a Boolean value indicating whether IE is the top-level container of the webbrowser control. True is returned.

type: return the type of the object loaded by the webbrowser control. For example, if the cmd.doc file, return to
Microsoft Word document
left or set the distance between the left side of the webbrowser control window and the left side of the container window
top or set the webbrowser control window the distance between the left side and the top side of the container window
width returns or sets the width of the webbrowser window, in pixels
height return or set the height of the webbrowser window, in pixels
locationname returns a string containing the name of the resources currently displayed in webbrowser, if the resource
is a webpage, It is the webpage title; if it is a file or folder, is the name of the file or folder
locationurl to return the URL of the resource currently being displayed in webbrowser
busy returns a Boolean value indicating whether webbrowser is loading the URL, if true is returned,
you can use the stop method to cancel ongoing access operations.

webbrowser event
private events description
triggered before beforenavigate2 navigation, not refreshed
commandstatechange is triggered when the command activation status changes. It indicates when to activate or disable the back and forward
menu item or button
documentcomplete. When the entire document is completed, refreshing the page does not trigger
downloadbegin. When a download operation starts, the refresh event can also be triggered.
downloadcomplete is triggered when a download operation is completed, a refresh event can also be triggered when the
navigatecomplete2 navigation is complete, but not when the refresh event is completed.
newwindow2 is triggered before the new window is created.
onfullscreen is triggered when the fullscreen attribute is changed. This event uses a varient_bool input parameter
to indicate whether IE is displayed in full screen mode (varient_true) or normal mode (varient_false).
onmenubar is triggered when the menubar attribute is changed, the parameter is of the varient_bool type.
variant_true is visible, and Variant _ false is hidden
whether the user closes the browser or the developer calls the quit method, when ie exits,
the onstatusbar method is the same as that called by onmenubar, indicating whether the status bar is visible.
the ontoolbar call method is the same as above, indicating whether the toolbar is visible.
the onvisible control window is visible or hidden. A varient_bool parameter is also used.
statustextchange is triggered if you want to change the text in the status bar, however, it does not care whether the program has a status bar
when titlechange title is valid or changed
webbrowser skills (favorites)

Ccommand editmode) has many drawbacks, such as the inability to display the selected text. In addition, some methods do not need to be listed one by one.

What I want to mention here is about mshtml. htmldocument

Reference Microsoft HTML Object Library

Rem # form code #

Dim withevents m_dom as mshtml. htmldocument
Private function m_dom_oncontextmenu () as Boolean
M_dom_oncontextmenu = false
End Function

Private sub webbrowser1_downloadcomplete ()
Set m_dom = webbrowser1.document
End sub

Rem okay, right-click the menu and no more

========================================================== ====================================

Call the control and get it from favorites

Basically, you can get the path of the favorites folder by using specialfolder (6). Then you can use dir to read each directory cyclically, and then the file in Dir, the file name is the name you want to add to favorites. The path can be obtained by yourself based on the Path obtained above.
If you do not need Dir, you can also use the Dir control of VB.
Private type shitemid
CB as long
Abid as byte
End type

Public type itemidlist
Mkid as shitemid
End type
Public Function specialfolder (byref csidl as long) as string
Locate the favorites folder
Dim R as long
Dim Spath as string
Dim IDL as itemidlist
Const noerror = 0
Const max_length = 260
R = shgetspecialfolderlocation (mdimain. hwnd, csidl, IDL)
If R = noerror then
Spath = space $ (max_length)
R = shgetpathfromidlist (byval IDL. mkid. CB, byval Spath)
If r then
Specialfolder = left $ (Spath, instr (Spath, vbnullchar)-1)
End if
End if
End Function
========================================================== ======================================

Yes, webbrowser is a control. You want it to be full screen, that is, the full screen of the form in which it is located. You can use setwindowlong to cancel the title of the form and call showwindow (findwindow (shell_traywnd ,), 0) Hide tray, that is, the line containing the start line below. use call showwindow (findwindow (shell_traywnd,), 9) to restore. enough details.

Then in form1.windowstate = 2.

========================================================== ======================================
Select the content on the webpage.
Private sub commandementclick ()
Please select some content first
Me. webbrowser1.execwb olecmdid_copy, olecmdexecopt_dodefault
Msgbox clipboard. gettext
End sub

========================================================== ==================================
Use IE to download files
Private declare function dofiledownload lib shdocvw. dll (byval lpszfile as string) as long

Private sub commandementclick ()

Dim sdownload as string

Sdownload = strconv (text1.text, vbunicode)
Call dofiledownload (sdownload)

End sub

Save HTML content in webbrowser
Dim OPF as ipersistfile
Set OPF = webbrowser1.document
OPF. Save "thefilenamehere.htm", false

How to Use webbrowser1.execwb

Below are the parameters I tested
WB. execwb (4, 1)

4. 1 save the webpage
4, 2 Save the webpage (you can rename it)
6, 1 print directly
6, 2 print directly
7, 1 print preview
7, 2 print and preview
8, 1 select parameters
8, 2 select parameters
10, 1 view page properties
10, 2 view page properties
Select All 17,1
Select All 17,2
Reload the current page
Reload the current page

Webbrowser confirmation dialog box
Webbrowser confirmation dialog box

For various reasons, some web pages will pop up a dialog box asking for information confirmation, which will often interrupt our webbrowser process. You can use the following method:
1. Add Microsoft HTML Object
2. Add a statement

Private sub webbrowser1_navigatecomplete2 (byval Pdisp as object, URL as variant)
Dim OBJ as htmldocument
Set OBJ = Pdisp. Document
Obj.parentwindow.exe cscript "function showmodaldialog () {return;}" 'determines the dialog box caused by showmodaldialog
End sub
The dialog confirmation box triggered by confirm can replace showmodaldialog with confirm, and alert can be the same ~

Webbrowser obtains the webpage source code private sub commandementclick ()
Webbrowser1.navigate "http://www.sdqx.gov.cn/sdcity.php"
End sub

Private sub webbrowser1_downloadcomplete ()
'Page download complete
Dim doc, objhtml
Set Doc = webbrowser1.document

Set objhtml = Doc. Body. createTextRange ()
If not isnull (objhtml) then
Text1.text = objhtml.html text
End if

End sub

I used webbrowser to get the webpage source code and directly run normally, but an error occurred after compilation.

Tip: Real-time error "91" object variable or with block variable is not set
It may be because the download is not complete,

Private sub webbrowser1_downloadcomplete ()
If webbrowser. Busy = false then
Dim doc, objhtml
Set Doc = webbrowser1.document

Set objhtml = Doc. Body. createTextRange ()
If not isnull (objhtml) then
Text1.text = objhtml.html text
End if
End if
End sub

A.htm
----------------------
<HTML>
<Head>
<SCRIPT>
VaR OBJ;
</SCRIPT>
</Head>
<Body>
<A href = # onclick = "obj. W (); Return false;"> asdasdsad </a>
</Body>
</Html>

Create an EXE and place a webbrowser control on the form.
Private sub form_load ()
Web. navigate "C: \ a.htm"
Doevents
Do
While
Web. Busy
Doevents
Loop
Set web. Document. parentwindow. OBJ = me
End sub

Public sub W ()
Msgbox "Haha"
End sub

 

Submit data in post Mode

Option explicit

Private sub commandementclick ()
Dim szvalue as string
Webbrowser1.document. body. innerhtml = "<Form ID = POST method = post action = http: // address/xxx. php> <input type = text value = '"& szvalue &"'> </form>"
Webbrowser1.document. Forms ("Post"). Submit
End sub

Private sub form_load ()
Webbrowser1.navigate2 "about: blank"
End sub

 

 

 

 

==================

Related Article

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.