|
-
Jun 17th, 2008, 02:30 PM
#1
Thread Starter
Member
[RESOLVED] Help With Kleinma's Suppressing Javascript Alerts in WebBrowser
I have a module that makes heavy use of code developed by Kleinma. (His work available here)
I have made some minor modifications, in that I call alertCheck() as a function. Also, I have it returning a Boolean so I know whether it had to close a javascript alert.
In a nutshell, I am setting up users for a web site. I have a MainForm, with a WebBrowser1. I also have an AddUserForm. When the AddUserForm is ran, it attempts to add a user to the site via the WebBrowser1 control. If the email address that the application is creating using their first initial and last name is already taken, then the site pops a javascript alert when we attempt to save.
What I would like is to use the alertCheck() module to handle the javascript alert if it is there, and then to return the boolean so we know that we need to try a different email address format.
The problem is that instead of closing the javascript alert, it is currently closing the MainForm application window, closing the program.
Can anyone see why that might be happening?
vb Code:
Imports System.Runtime.InteropServices
Module JSAlertHandlerModule
'DLL IMPORTED FUNCTIONS FOR GETTING ACTIVE JS ALERT BOX AND SENDING A CLOSE MESSAGE TO IT
<DllImport("user32.dll")> _
Function GetLastActivePopup(ByVal hwnd As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Function PostMessage( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As IntPtr, _
ByVal lParam As IntPtr) As Boolean
End Function
Function alertCheck() As Boolean
'GET HANDLE OF LAST ACTIVE POPUP (AKA JS ALERT)
Dim PopupHandle As IntPtr = GetLastActivePopup(MainForm.Handle)
Dim alertsCounted As Integer = "0"
'IF THE POPUP HANDLE IS NOT 0, AND IT IS NOT THE WB HANDLE
'THEN SEND A WM_CLOSE MESSAGE (&H10) TO THE POPUP
If (PopupHandle <> IntPtr.Zero) AndAlso (PopupHandle <> MainForm.WebBrowser1.Handle) Then
'MsgBox(PopupHandle.ToString & " = " & MainForm.WebBrowser1.Handle.ToString)
PostMessage(PopupHandle, &H10, New IntPtr(1), IntPtr.Zero)
alertsCounted = alertsCounted + 1
End If
'If we had to close any, then we return TRUE. Otherwise, FALSE.
If alertsCounted > 0 Then
Return True
Else
Return False
End If
End Function
End Module
Last edited by GeekInOhio; Jun 18th, 2008 at 12:37 PM.
Reason: Clarification.
In case I forget: I'm using Visual Basic 2008 Express Edition...
Should I, in my odd, bumbling way, actually offer some assistance, feel free to show me some RATE love.
Just Another Laptop Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|