1.WebBrowser打開網站代碼為:WebBrowser1.Navigate "網址"
如打開百度代碼:WebBrowser1.Navigate "http://baidu.com"
如打開首頁代碼:WebBrowser1.Navigate "about:blank"
2.IE相關指令按鈕
重新整理:WebBrowser1.Refresh
停止:WebBrowser1.Stop
上一頁:
On Error GoTo lab
WebBrowser1.GoBack
Exit
Sub
lab:
msgox"沒有上一頁了"
下一頁:
On Error GoTo lab
WebBrowser1.GoForward
Exit
Sub
lab:
msgox"沒有下一頁了"
3.禁止右鍵菜單、滾動條、判斷是否加載完畢
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,
URL As Variant)
On Error Resume Next'忽略錯誤
Dim js$'調用腳本禁止WebBrowser1右鍵菜單
js = "document.body.οncοntextmenu=function()" &
vbCrLf & _
"{event.returnValue=false;}"
WebBrowser1.Document.parentWindow.execScript js, "javascript"
WebBrowser1.Document.currentviewMode = 4 '本地檔案清單視圖,可選範圍2-4
WebBrowser1.Document.body.Scroll = "no"
'yes顯示,NO隐藏WebBrowser1滾動條
If (pDisp Is WebBrowser1.object) Then
Label1.Caption = "完成" '判斷網頁是否加載完畢
End If
End Sub
4.頁面全部隻在目前控件中顯示
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As
Boolean)
On Error Resume Next
Cancel = True
WebBrowser1.Navigate
WebBrowser1.Document.activeelement.href'擷取滑鼠位置的連結并打開
End Sub
5.其它
顯示的頁面名稱:Label1.Caption = WebBrowser1.LocationName
PS:收藏的内容不斷更新中,歡迎大家補充....