Good afternoon. I am developing a gmail app for my personal consumption for now and it has a lot of bells and whistles including showing me the latest emails coming in, playing a sound and changing icon when there is new mail and a few other things. I am using the webbrowser control and reading the source etc from within the control and since my default browser is not IE, of course, I am trying to divert the URLs in the emails to open in my default browser which works fine, except everytime I click a link it pops up a box letting me know I am using a popup blocker and I should disable it for gmail to work better. I have tried to find the popup boxes code to remove it from the webbrowser control's display as well as a few other things and nothing works. Can anyone help me with disabling this popup? The code I am using to divert the link to my default browser is below and let me know if you need any more info.

Private Sub WebBrowser1_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

        Dim webbrowser As WebBrowser = sender

        OpenWebsite(webbrowser.StatusText.ToString())


        webbrowser = Nothing
        e.Cancel = True
    End Sub
    Public Sub OpenWebsite(url As String)
        'If Not System.IO.File.Exists("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") Then
        'Process.Start("C:\Program Files\Google\Chrome\Application\chrome.exe", url)
        'Else
        'Process.Start("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", url)
        'End If
        NavigateWebURL(url)
        'NavigateWebURL("http://www.google.com", "Firefox") '// safari Firefox chrome etc

        'Process.Start("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", url)
    End Sub
    Private Sub NavigateWebURL(ByVal URL As String, Optional browser As String = "default")

        If Not (browser = "default") Then
            Try
                '// try set browser if there was an error (browser not installed)
                Process.Start(browser, URL)
            Catch ex As Exception
                '// use default browser
                Process.Start(URL)
            End Try

        Else
            '// use default browser
            Process.Start(URL)

        End If

    End Sub

Thanks a bunch for taking a look and for any help you can give me!

Larry

Hello,
You could try disabling the popup blocker on the WebBrowser, opening the link then re-enabling the popup blocker. At the moment that is all I could think of as I just go out of bed.

Unless you can give me a little more information on the error/ issue you are having.

I have tried to do that but it seems the settings in IE may not be affecting the settings in my app's IE control, I have tried disabling the popup blocker in IE. What happens is I get the following popup in my app
e0de2fadca453a0e5f1dc27b116a0ba5

when I click a link and the IE control fires the WebBrowser1_NewWindow event. I understand it is a built in "feature" of IE but would love to know of a way to get it to stop doing it.

Thanks for taking a look at this, have a great day,
Larry

I get that popup in my app's browser control when I am diverting it to my default browser, Chrome at the current time. The popup is in my app not in Chrome.

Yes it is trying to open it up in chrome. What I am doing is creating a gmail app using the webbrowser control, but I want my links inside of emails to open in my default browser not in IE. The webbrowser control is thinking there is a popup blocker is preventing the link from opening since I am performing an e.cancel, This is causing the window opening.

Why don't you try this:
Private Sub WebBrowser1_NewWindow(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
Dim webbrowser As WebBrowser = sender
Process.Start(webbrowser.StatusText.ToString())
webbrowser = Nothing
e.Cancel = True
End Sub

Edited 2 Years Ago by joshl_1995

I still get the popup....I appreciate your help. I wish I could figure out what causing it, was thinking to try to use a chrome control but they seem very difficult to use.

The only alternative I can think of looking to see if there is a Gmail api for VB.net, then you can just design your own GUI. In a way that is what I would do.

Ok, thanks for your help. Was hoping to keep it more simple, I guess that is what I get for staying quick and simple, a popup. Going the API way may get rid of the popup but will add lots of work managing all of the things gmail does on its own.

Thanks again,
Larry

Ok figured it out using a weird way, just for anyone in the future that has this happen to them. This may not be 100% way of handling it but worked for me for the most part.

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If Not Timer1.Enabled Then Timer1_Tick(sender, e) : Timer1.Enabled = True

        For Each clsLink As HtmlElement In Me.WebBrowser1.Document.Links
            'the following line removes the handler just in case the documentcompleted fires twice or more
            RemoveHandler clsLink.Click, New System.Windows.Forms.HtmlElementEventHandler(AddressOf AnchorLink_Clicked)
            AddHandler clsLink.Click, New System.Windows.Forms.HtmlElementEventHandler(AddressOf AnchorLink_Clicked)
        Next
End Sub


Private Sub AnchorLink_Clicked(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
        'MessageBox.Show(Me, "Links are not allowed.")
        Dim sURL As String = CType(sender, HtmlElement).GetAttribute("href").ToLower()
        ' process...
        If sURL.Contains("mail.google.com") Then
            WebBrowser1.Navigate(sURL)
            'this allows the mail links to point back to this window
        Else
            'this will override the link firing to IE window and will force it to fire in default browser window
            Process.Start(CType(sender, HtmlElement).GetAttribute("href").ToString())
        End If
        ' cancel event in document...
        e.ReturnValue = False
End Sub

This will allow links to be followed in default browser if not part of gmail's links and allow gmail's links (inbox etc) to stay in the webbrowser control.

This question has already been answered. Start a new discussion instead.