1. 屏蔽右键菜单
在菜单中单击"工程"->"引用",在列表中找到"Microsoft HTML Object Library"打上勾,按确定就可以了。
然后自己加上控件
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
2.无边框以及和JS交互
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set M_Dom = WebBrowser1.Document
'Me.PopupMenu mymenu
' On Error Resume Next
pDisp.Document.body.setAttribute "extend", Me ‘用于和网页里的JS交互
With WebBrowser1 ‘无边框设置
.Document.body.Scroll = "no"
.Document.body.Style.border = "0px"
.Document.body.Style.margin = "0px"
.Document.body.Style.overflow = "hidden"
End With
End Sub
Function doSomething(ByVal sParam$)’处理网页里的事件
MsgBox sParam, vbInformation Or vbOKOnly, "doSomething"
End Function
在网页里调用VB程序里的doSomething:
<a href="void(0)" onclick="document.body.extend.doSomething('www.google.com-000000');return false;">google.com</a><br />