如何在C#或VB.Net Winform应用程序中的javascript警报/确认框上获得用户操作,如“确定”或“取消”
本文关键字:取消 确定 确认 操作 用户 警报 VB Net Winform javascript 应用程序 | 更新日期: 2023-09-27 18:20:34
我在Vb.Net WinForms应用程序中使用SHDocVw.InternetExplorer API来记录应用程序中Internet Explorer的用户操作。
通过使用"user32.dll"的"GetForegroundWindow",我可以获得确认框的句柄。我可以很容易地获得所需的信息,如"ClassName"answers"WindowText"。
现在我需要知道关闭确认框的用户操作,即用户按下"确定"或"取消"按钮?
这是我使用的示例代码
Private Function GetAlertMessage() As String
Dim hwnd = GetForegroundWindow
Dim ForeGroundWindowClassName As String = GetClassNameFromHandle(hwnd)
If String.CompareOrdinal("#32770", ForeGroundWindowClassName) = 0 Then
'Its definitely an alert
Dim AlertMessage As String = String.Empty
For Each childWin As WindowChildInfo In GetChildWindows(hwnd)
If childWin.ClassName.ToLower = "static" Then
AlertMessage = childWin.Text
End If
Next
Return AlertMessage
End If
End Function
Public Function GetClassNameFromHandle(ByVal hWnd As Integer) As String
Dim sbClassName As New Text.StringBuilder("", 256)
Call GetClassName(hWnd, sbClassName, 256)
Return sbClassName.ToString
End Function
Private children As List(Of WindowChildInfo)
Public Function GetChildWindows(ByVal hwnd As Integer) As List(Of WindowChildInfo)
children = New List(Of WindowChildInfo)
EnumChildWindows(hwnd, AddressOf EnumProc, Nothing)
Return children
End Function
Private Function EnumProc(ByVal hwnd As Integer, ByVal lParam As Integer) As Integer
If hwnd <> 0 Then
children.Add(New WindowChildInfo(hwnd, GetClassNameFromHandle(hwnd), GetText(hwnd)))
End If
Return 1
End Function
如果我答对了你的问题,那么你需要在javascript中使用confirm。
var action= confirm("your message here");
如果用户按ok,则返回true;如果用户按cancel,则返回false。