实现代码:
Private WithEvents HtmlDocument As MSHTML.HtmlDocument Private WithEvents HtmlElement As MSHTML.HTMLButtonElement 'code by lichmama from cnblogs.com Private Sub Form_Load() With WebBrowser1 .Left = 0 .Top = 0 .Navigate "file://C:\Users\Administrator\Desktop\test.html" End With End Sub Private Sub Form_Resize() With WebBrowser1 .Width = Me.Width .Height = Me.Height End With End Sub Private Sub Form_Unload(Cancel As Integer) Set HtmlElement = Nothing Set HtmlDocument = Nothing End Sub Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) With WebBrowser1 'get the HtmlDocument from webbrowser, ' and bind the control of button to [HtmlElement], ' and setup the event handler of [mybutton]'s onclick. Set HtmlDocument = .Document Set HtmlElement = HtmlDocument.getElementById("submit") End With End Sub Private Function HtmlDocument_oncontextmenu() As Boolean '屏蔽右键菜单 HtmlDocument_oncontextmenu = False End Function Private Function HtmlElement_OnClick() As Boolean 'in this section, we can do any operations to current page. ' think about it, if this is a submit button, we could verify the password, whatever. username = HtmlDocument.getElementById("login_username").Value password = HtmlDocument.getElementById("login_password").Value Debug.Print "your username:", username Debug.Print "your password:", password HtmlElement_OnClick = False End Function
test.html(@http://www.jb51.net/css/97304.html):
View Code
然后,让我们来看看效果:
了解更多请访问:http://www.ndfweb.cn/news-733.html