[英]How to detect if there is running Javascript in an VB.NET WebBrowser-object
情況:
使用VB.NET Framework 3.5和Visual Studio 2005,我創建了一個使用WebBrowser對象的項目。 分解為最基本的內容,它看起來像:
Dim bWbCompletedDocument As Boolean = False
Sub WbCompletedDocument(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
bWbCompletedDocument = True
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)Handles Me.Load
Dim th As New System.Threading.Thread(AddressOf worker)
th.SetApartmentState(Threading.ApartmentState.STA)
th.Start()
End Sub
Sub worker()
Dim Wb As New WebBrowser
Wb.ScriptErrorsSuppressed = True
AddHandler Wb.DocumentCompleted, AddressOf WbCompletedDocument
Wb.Navigate("google.de")
Dim start As Date = Now
Do While start.AddSeconds(20) > Now
Application.DoEvents()
If (bWbCompletedDocument = True) And (Wb.IsBusy = False) And (Wb.ReadyState = WebBrowserReadyState.Complete) Then
Exit Do
End If
Loop
If bWbCompletedDocument = False Then
Exit Sub
End If
'more code here
End Sub
沒有瀏覽器的GUI,但一切正常。 我導航到捕獲DocumentCompleted -event的頁面,檢查ReadyState以及是否為IsBuisy並繼續執行我的代碼。
問題
當onLoad -Event發生時,有一些站點開始執行JavaScript代碼。 如果在Wb對象加載Page之后僅繼續執行.Net代碼,則Wb將停止執行JavaScript。
問題
是否可以確定WebBrowser對象中當前是否正在運行JavaScript和/或等待其完成?
如果您能夠在頁面上添加JavaScript,則可以在正確的時刻引發一個事件以向.NET應用程序發出信號。 或者,您可以在javascript中設置狀態,然后讓.NET應用程序對其進行輪詢。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.