Webbrowser控件史上最强技巧全集解析 下载本文

Webbrowser控件史上最强技巧全集 VB调用webbrowser技巧集 1、获得浏览器信息:

Private Sub Command1_Click()

WebBrowser1.Navigate \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

点击Command1浏览网页,点击Command2在立即窗口中输出浏览器信息。

2、弹出Webbrowser消息窗口

Dim oWindow

Set oWindow = WebBrowser1.Document.parentWindow oWindow.confirm \

VB调用webbrowser技巧集2

向Webbrowser中写入HTML内容的几种方法

首先在Form_Load中加入

WebBrowser1.Navigate \

确保Webbrowser1可用 方法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 方法2: Dim o

Set o = WebBrowser1.Document.selection.createrange Debug.Print o

If (Not o Is Nothing) Then o.pasteHTML \哈哈\Set o = Nothing End If 方法3:

'插入文本框 Dim o

Set o = WebBrowser1.Document.selection.createrange

o.execCommand \

vb调用Webbrowser技巧集3 1、页面滚动:

Private Sub Command2_Click()

WebBrowser1.Document.parentwindow.scrollby 0, 30 End Sub

Private Sub Form_Load()

WebBrowser1.Navigate \End Sub

点击Command2就可以使当前页面向下滚动30像素

2、判断页面是否可以前进后退

Private Sub Command1_Click() WebBrowser1.GoForward End Sub

Private Sub Command2_Click() WebBrowser1.GoBack End Sub

Private Sub Form_Load()

WebBrowser1.Navigate \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

VB调用webbrowser技巧集4

1、如何使网页不出现滚动条:

Private Sub mnuScroll1_Click()

@#注意:必须在网页完全显示之后才可以运行

WebBrowser1.Document.body.Scroll = \不显示滚动条的办法 End Sub

Private Sub mnuScroll2_Click()

@#注意:必须在网页完全显示之后才可以运行

WebBrowser1.Document.body.Scroll = \显示滚动条的办法 End Sub

2、如何获得网页中被选中部分的HTML:

Private Sub Command1_Click() Dim objSelection Dim objTxtRange