|
-
Aug 24th, 2003, 04:00 AM
#1
Thread Starter
Lively Member
'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?
-
Aug 24th, 2003, 11:34 AM
#2
Fanatic Member
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:
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Cancel = True
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:
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)
If InStr(1, URL, "window.external.AddFavorite", vbTextCompare) <> 0 Then Cancel = True
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
-
Aug 24th, 2003, 12:47 PM
#3
Fanatic Member
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:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim i As Integer
For i = 0 To WebBrowser1.Document.links.length - 1
If InStr(1, WebBrowser1.Document.links(i).outerHTML, "window.external.AddFavorite", vbTextCompare) <> 0 Then
If WebBrowser1.Document.links(i).getAttribute("onclick") <> vbNullString Then
If InStr(1, WebBrowser1.Document.links(i).getAttribute("onclick"), "window.external.AddFavorite", vbTextCompare) Then WebBrowser1.Document.links(i).setAttribute "onclick", vbNullString
End If
If WebBrowser1.Document.links(i).getAttribute("onkeydown") <> vbNullString Then
If InStr(1, WebBrowser1.Document.links(i).getAttribute("onkeydown"), "window.external.AddFavorite", vbTextCompare) Then WebBrowser1.Document.links(i).setAttribute "onkeydown", vbNullString
End If
End If
Next
End Sub
Author for Visual Basic Web Magazine
-
Dec 7th, 2003, 01:19 PM
#4
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|