Web浏览器执行Javascript

时间:2016-07-21 11:26:05

标签: javascript asp.net vb.net webbrowser-control

我有一些像这样的代码:

Public Sub runBrowserThread()
        Dim th As Thread = New Thread(AddressOf TestThread)
        th.SetApartmentState(ApartmentState.STA)
        th.Start()
    End Sub

    Private Sub TestThread()
        Dim br As WebBrowser = New WebBrowser()
        AddHandler br.DocumentCompleted, AddressOf browser_DocumentCompleted
        AddHandler br.Navigating, AddressOf Me.Navigating
        br.Navigate("http://localhost:55623/test.aspx")
        Application.Run()
    End Sub

    Public Sub Navigating(sender As Object, e As WebBrowserNavigatingEventArgs)
        MsgBox("Got here")
    End Sub

    Private Sub browser_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
        Dim br = TryCast(sender, WebBrowser)
        br.Document.InvokeScript("LoadAjax")
        If br.Url = e.Url Then
            Console.WriteLine("Natigated to {0}", e.Url)
            ' Stops the thread
            Application.ExitThread()
        End If
    End Sub

Test.aspx包含运行onload的JavaScript代码。但是,它不在webbrowser上下文中执行。我该如何执行JavaScript?

0 个答案:

没有答案