Results 1 to 15 of 15

Thread: [RESOLVED] Help With Kleinma's Suppressing Javascript Alerts in WebBrowser

Threaded View

  1. #1

    Thread Starter
    Member GeekInOhio's Avatar
    Join Date
    Jun 2008
    Location
    You'll never guess...
    Posts
    56

    Resolved [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:
    1. Imports System.Runtime.InteropServices
    2.  
    3. Module JSAlertHandlerModule
    4.  
    5.  
    6.  
    7.  
    8.     'DLL IMPORTED FUNCTIONS FOR GETTING ACTIVE JS ALERT BOX AND SENDING A CLOSE MESSAGE TO IT
    9.     <DllImport("user32.dll")> _
    10.     Function GetLastActivePopup(ByVal hwnd As IntPtr) As IntPtr
    11.     End Function
    12.  
    13.     <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    14.     Function PostMessage( _
    15.                              ByVal hWnd As IntPtr, _
    16.                              ByVal Msg As Integer, _
    17.                              ByVal wParam As IntPtr, _
    18.                              ByVal lParam As IntPtr) As Boolean
    19.     End Function
    20.  
    21.  
    22.  
    23.     Function alertCheck() As Boolean
    24.  
    25.         'GET HANDLE OF LAST ACTIVE  POPUP (AKA JS ALERT)
    26.         Dim PopupHandle As IntPtr = GetLastActivePopup(MainForm.Handle)
    27.         Dim alertsCounted As Integer = "0"
    28.  
    29.         'IF THE POPUP HANDLE IS NOT 0, AND IT IS NOT THE WB HANDLE
    30.         'THEN SEND A WM_CLOSE MESSAGE (&H10) TO THE POPUP
    31.         If (PopupHandle <> IntPtr.Zero) AndAlso (PopupHandle <> MainForm.WebBrowser1.Handle) Then
    32.             'MsgBox(PopupHandle.ToString & " = " & MainForm.WebBrowser1.Handle.ToString)
    33.  
    34.             PostMessage(PopupHandle, &H10, New IntPtr(1), IntPtr.Zero)
    35.             alertsCounted = alertsCounted + 1
    36.         End If
    37.  
    38.         'If we had to close any, then we return TRUE. Otherwise, FALSE.
    39.  
    40.         If alertsCounted > 0 Then
    41.             Return True
    42.         Else
    43.             Return False
    44.         End If
    45.  
    46.     End Function
    47.  
    48.  
    49.  
    50. 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
  •  



Click Here to Expand Forum to Full Width