how to know if gecko browser completed loading a webpage?

独自空忆成欢 提交于 2019-12-25 02:48:12

问题


As the title says, how can i know if the gecko browser completed loading a web page? I know there is document_completed event. But it will get triggered for every time a web page loads. Are there any other ways to check if the current webpage is completed loading.


回答1:


Do While WebBrowser.IsBusy = True
Application.DoEvents()
Loop

Works for me. After WebBrowser.Navigate you have to wait for some time (I use 1 second) before IsBusy becomes True




回答2:


My Solotion in vb.net and GeckoFX v45.0.34.0 you can use this tool convert to c# (http://converter.telerik.com/):

Private vWeb As GeckoWebBrowser = New GeckoWebBrowser
Private Property pageready As Boolean = False

Private Sub WaitForPageLoad()
    AddHandler vWeb.DocumentCompleted, New EventHandler(Of GeckoDocumentCompletedEventArgs)(AddressOf PageWaiter)

    While Not pageready
        Application.DoEvents()
    End While

    pageready = False
End Sub

Private Sub PageWaiter(ByVal sender As Object, ByVal e As GeckoDocumentCompletedEventArgs)
    If vWeb.IsBusy = False Then
        pageready = True
        RemoveHandler vWeb.DocumentCompleted, New EventHandler(Of GeckoDocumentCompletedEventArgs)(AddressOf PageWaiter)
    End If
End Sub

Using:

vWeb.Navigate("https://www.google.com")
WaitForPageLoad()
//Do your Work

Hope this solution to resolve.



来源:https://stackoverflow.com/questions/33116446/how-to-know-if-gecko-browser-completed-loading-a-webpage

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