How to Block Pop Up with WebBrowser Control

Discussion in 'General Programming Chat' started by iamblackhat, Nov 24, 2008.

  1. iamblackhat

    iamblackhat Registered Member

    Joined:
    Feb 6, 2008
    Messages:
    63
    Likes Received:
    9
    Hi guys, I'm trying to create a simple application using the WebBrowser control.

    When I visit a certain website using the webbrowser control, a pop up window appears. Is there anyway to block this pop up using the WebBrowser control?
     
  2. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,943
    Likes Received:
    1,948
    Most peoples computers have a popup blocker anyway.
     
  3. iamblackhat

    iamblackhat Registered Member

    Joined:
    Feb 6, 2008
    Messages:
    63
    Likes Received:
    9
    That may be, but I would still like to know how to do this.
     
  4. lamlam

    lamlam Junior Member

    Joined:
    Oct 25, 2008
    Messages:
    134
    Likes Received:
    854
    Occupation:
    What do you think?
    Location:
    In my home...
    Code:
     If WebBrowser1.Url.ToString = "popup url" Then
                WebBrowser1.Navigate("destination url")
            End If
    
    That's the most basic thing I cam up with in 30 seconds... If you're using C#, it shouldn't be too hard. You get the idea of what this does. You can expand on this a lot, but this is quite basic.
     
  5. the_demon

    the_demon Jr. Executive VIP

    Joined:
    Nov 23, 2008
    Messages:
    3,231
    Likes Received:
    1,596
    Occupation:
    Search Engine Marketing
    Location:
    The Internet
    Firefox + "adblock+" + noscript = NO POPUPS

    Not sure about code 4 u though.
     
  6. Celtik

    Celtik Registered Member

    Joined:
    Apr 23, 2008
    Messages:
    51
    Likes Received:
    2
    Also, try this:

    webbrowser1.silent=true
     
  7. Celtik

    Celtik Registered Member

    Joined:
    Apr 23, 2008
    Messages:
    51
    Likes Received:
    2
    Just saw this on vbforums.com:

    Code:
    Private Function IsPopupWindow() As Boolean
    
          On Error Resume Next
    
          If WebBrowser1.Document.activeElement.tagName = "BODY" Or WebBrowser1.Document.activeElement.tagName = "IFRAME" Then
       
          IsPopupWindow = True
    
          Else
    
          IsPopupWindow = False
    
          End If
    
          End Function
    
           
    
          Private Sub webbrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    
          Dim frm As Form1
    
          Cancel = IsPopupWindow
    
          If Cancel = False Then
    
          Set frm = New Form1
    
          Set ppDisp = frm.WebBrowser1.object
    
          frm.Show
    
          End If
    
          End Sub 
     
  8. bbyte

    bbyte Registered Member

    Joined:
    Oct 24, 2008
    Messages:
    86
    Likes Received:
    70
    He's talking about a popup blocker for the VB.net WebBrowser control, it's a webbrowser itself, so it obviously won't use your own browser's popup blocker.

    I'd use the code mentioned above :)
     
  9. andygabon

    andygabon BANNED BANNED

    Joined:
    Nov 20, 2007
    Messages:
    67
    Likes Received:
    70
    yup, the only simple way to block the popup from the WB control is thru NewWindow2 property (just put cancel=true)

    but sometime, it can't block all the popup. dunno with the new version of IE. it all affected by the client's IE settings.