webbrowser中有js弹出的对话(alert)请问如何获取弹出窗口的内容!

解决方案 »

  1.   

    看看:http://www.mvps.org/emorcillo/en/code/vb6/index.shtml 
    这里面有一些定制WebBrowser的例子
      

  2.   

    或者实现IDocHostShowUI接口http://hi.baidu.com/tanjian/blog/item/5b989345c0eace3f87947399.html
      

  3.   

    引用Microsoft HTML Object LibraryOption Explicit
    Private WithEvents m_MyVar As HTMLInputElementPrivate Sub Form_Load()
        WebBrowser1.Navigate2 "f:\test.html"
    End SubPrivate Function m_MyVar_onchange() As Boolean
        MsgBox "alert的内容是: " & m_MyVar.Value
    End FunctionPrivate Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
        Dim oWindow As HTMLWindow2
        Dim oDoc As HTMLDocument
        
        Set oDoc = pDisp.Document
        Set oWindow = oDoc.parentWindow
        
        Set m_MyVar = oDoc.createElement("input")
        m_MyVar.Type = "Hidden"
        m_MyVar.id = "MyVar"
        
        oDoc.getElementsByTagName("BODY").Item(0).appendChild m_MyVar
        oWindow.execScript "var oldalert=window.alert;window.alert=function myalert(msg){MyVar.value=msg;MyVar.fireEvent(""onchange"");oldalert(msg);};"
    End Sub