Results 1 to 4 of 4

Thread: 'cancel' pop up alerts in the webbrowser control?

  1. #1

    Thread Starter
    Lively Member Scorpion965's Avatar
    Join Date
    Jan 2002
    Location
    Laguna Hills, CA
    Posts
    100

    'cancel' pop up alerts in the webbrowser control?

    Hello...

    I have a webbrowser control integrated into my program that must connect to a remote server which is located on host that uses a variety of advertising methods, including recently automatically popping up the 'add to favorites' box - the webbrowser I am using has its silent property set to 'true' at runtime, but I am still getting these 'add to favorites' boxes despite this silent property, even worse the browser will open up additional ad popups when the 'add to favorites' box is up and apparently silent can do nothing to stop them, it sometimes even leads to system crashes... is there any way to disable these alerts? I thought the silent property was supposed to disable all kinds of notification through the webbrowser? Is there anyway to 'cancel' these alerts automatically once they have been popped up?

  2. #2
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    Okay, here are a few solutions...

    This code will block popup windows (if you don't need to block all of them, first check the URL before blocking...).
    VB Code:
    1. Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    2. Cancel = True
    3. End Sub

    This code checks the URL of a clicked link for the phrase 'window.external.AddFavorite', which opens the Favorites window; if it's in the link, it's blocked.
    VB Code:
    1. Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    2. If InStr(1, URL, "window.external.AddFavorite", vbTextCompare) <> 0 Then Cancel = True
    3. End Sub

    Now there's one unresolved situation: if a link has a '#' as href attribute, but uses an onClick atribute to open a window or shows the AddFavorite window. I'll think about that one for a while...
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  3. #3
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871
    After some thinking I came up with this solution. There doesn't seem to be a way to tell which link was clicked, so after a page has loaded you should loop through all links and erase the AddFavorite links. This code does that, and thus checks the onClick and onKeyDown attribute. You should include all possible attributes...
    VB Code:
    1. Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    2. Dim i As Integer
    3.  
    4. For i = 0 To WebBrowser1.Document.links.length - 1
    5.     If InStr(1, WebBrowser1.Document.links(i).outerHTML, "window.external.AddFavorite", vbTextCompare) <> 0 Then
    6.         If WebBrowser1.Document.links(i).getAttribute("onclick") <> vbNullString Then
    7.             If InStr(1, WebBrowser1.Document.links(i).getAttribute("onclick"), "window.external.AddFavorite", vbTextCompare) Then WebBrowser1.Document.links(i).setAttribute "onclick", vbNullString
    8.         End If
    9.         If WebBrowser1.Document.links(i).getAttribute("onkeydown") <> vbNullString Then
    10.             If InStr(1, WebBrowser1.Document.links(i).getAttribute("onkeydown"), "window.external.AddFavorite", vbTextCompare) Then WebBrowser1.Document.links(i).setAttribute "onkeydown", vbNullString
    11.         End If
    12.     End If
    13. Next
    14. End Sub
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  4. #4
    Fanatic Member MikkyThomeon's Avatar
    Join Date
    Oct 2002
    Location
    At work...
    Posts
    648
    Another possible problem here is that if a file dowload link is encountered, the notification dialog box will pop up and there is NO WAY to cancel it!!!! Even silent mode does not work.

    Although my application is different I eventually went with using the Inet control

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