0

VBA では、javascript onchange イベントをインターセプトして、webbrowser コントロールで元の ID 番号を取得することは可能ですか?

<select name="status0" id="status0" onchange="javascriptonchangeeventhere">

上記のコードはコンボボックスのデモです。コンボボックスから項目を選択すると、javascript で onchange が処理されます。現在の日付と参照番号を含むフォームをプルアップするのではなく、自分のユーザーフォームをプルアップして、そのデータを関連する (notes0) フィールドに吐き出します。これが発生したときにどのようにインターセプトして、正しいフィールドに割り当てることができるでしょうか。

4

1 に答える 1

2

ここに短い例があります。「Microsoft HTML オブジェクト ライブラリ」および「Microsoft インターネット コントロール」のプロジェクト参照セット

クラス モジュール「clsEvents」で:

Option Explicit

Public WithEvents slct As MSHTML.HTMLSelectElement
Public WithEvents href As MSHTML.HTMLAnchorElement

'Note that having defined "href" as "WithEvents", if you choose "href"
'  from the left-hand dropdown at the top of the class code module
'  then the right-hand dropdown will populate with events you can select
'  from to create an event-handling procedure in the class

Private Function href_onclick() As Boolean
    Debug.Print "link clicked"
    href_onclick = False 'cancels the navigation
End Function

Private Sub slct_onchange()
    Debug.Print "select onchange - value is " & slct.Value
End Sub

Private Function slct_onclick() As Boolean
    Debug.Print "select onclick - value is " & slct.Value
End Function

通常のモジュールでは:

Option Explicit

Dim evt As clsEvents

Sub Setup()

    Dim IE As New InternetExplorer
    Dim el As Object, el2 As Object

    Set evt = New clsEvents

    IE.Visible = True
    IE.navigate "http://www.csee.wvu.edu/~riggs/html/select_example.html"

    Do While IE.Busy
    Loop

    Set el = IE.document.getElementsByTagName("select")(1)
    Set el2 = IE.document.getElementsByTagName("a")(1)

    If Not el Is Nothing Then
        Debug.Print "setting event capture: currentvalue=" & el.Value
        Set evt.slct = el
    End If

    If Not el2 Is Nothing Then
        Debug.Print "setting event capture on link:" & el2.innerText
        Set evt.href = el2
    End If

End Sub

サブルーチンを実行してSetupから、2 番目の選択の値を変更するか、IE のページで「Javascript」リンクをクリックすると、VB エディタのイミディエイト ウィンドウに出力が表示されます。

始めるのに役立つことを願っています。

于 2012-10-17T05:54:28.930 に答える