VB6: get onreadystate value from browser control

久未见 提交于 2019-12-11 18:16:08

问题


i'm trying to get the onreadystate value from the browser control do detect when the page has finished loading. unfortunately the event's .returnValue returns empty. what's wrong?

here's my code - thx:

Dim WithEvents m_doc As HTMLDocument

Private Sub Form_Load()
    Set m_doc = WebBrowser1.Document
End Sub

Private Sub m_doc_onreadystatechange()
Dim m_event As IHTMLEventObj
    Set m_event = m_doc.parentWindow.event
    m_value = "'" & m_event.returnValue & "'"
    MsgBox "onreadystatechange: " & m_value
End Sub

回答1:


If you want to use the HTMLDocument's events try

m_doc.createDocumentFromUrl "http://www.microsoft.com", ""

Otherwise you can use the WebBrowser control's event to detect when a document is completely loaded or call the Navigate or Navigate2 method and immediately loop while polling the WebBrowser.ReadyState

WebBrowse1.Navigate2 "http://www.microsoft.com"
Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Of course don't forget to add an error handler.



来源:https://stackoverflow.com/questions/2567075/vb6-get-onreadystate-value-from-browser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!