VS 2010 How to open a webbrowser link in a new tab.-VBForums
Results 1 to 8 of 8

Thread: How to open a webbrowser link in a new tab.

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    How to open a webbrowser link in a new tab.

    Hi everyone!
    I ran into a problem while creating a web-browser. Whenever I click on a link/button in the web-browser that redirects to a new page, IE pops up with the URL. I was able to open a tab and cancel the ie operation, but I still don't know how to make the link that was supposed to load up in the ie browser load up in the new tab. Any help is appreciate, thank-you in advance.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,171

    Re: How to open a webbrowser link in a new tab.

    Hi johnwillmikul, this question has been asked quite a bit. So it's not uncommon that you're experiencing this kind of trouble. The quick fix is to add this code in the webbrowser's newwindow event:

    Code:
            'This creates a new tab
            Dim tp As New TabPage
            TabControl1.Controls.Add(tp)
    
            'This creates a new webbrowser with the NewWindow Event
            'And navigates it to the link wanting to be opened
            Dim wb As New WebBrowser
            Dim myElement As HtmlElement = WebBrowser1.Document.ActiveElement
            Dim target As String = myElement.GetAttribute("href")
            With wb
                .Navigate(target)
                .Dock = DockStyle.Fill
            End With
    
            AddHandler wb.NewWindow, AddressOf WebBrowser_NewWindow
    
            tp.Controls.Add(wb)
    
            'This prevents ie from popping up
            e.Cancel = True

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: How to open a webbrowser link in a new tab.

    Hi, thanks for the code . I just have one problem though, when I click on a button that is supposed to open a link in a new tab, I get an error that says "Unable to get the value of property 'closed' object is null or undefined". Then a tab is opened with the webbrowser navigating to the blank page. I really need to fix this. The code above was great though, and works for hyperlinks. Thank you, and please reply if u know what to do.

    Name:  scrip error.png
Views: 3791
Size:  212.6 KB
    Last edited by johnwillmikul; Mar 6th, 2013 at 04:28 PM.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: How to open a webbrowser link in a new tab.

    That's a javascript error. Nothing to do with your program (well, not directly!) You can suppress javascript errors using the ScriptErrorsSuppressed property.If you want the javascript to run perfectly, there are some things you can try but no guarantees.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: How to open a webbrowser link in a new tab.

    Yeah, I can see it's a java-scrip error...but is there any way to navigate to the link the button should redirect to, as it does in chrome and other webbrowsers? It redirects to a blank page when what it's sposed to do is open a poppup. I did have ScriptErrorsSuppressed on, but turned it off when I recieved a blank page to see if I would get an error.
    Last edited by johnwillmikul; Mar 6th, 2013 at 04:47 PM.

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,171

    Re: How to open a webbrowser link in a new tab.

    I'm not to sure about that because I try to stay away from that sorta thing. Perhaps dunfiddlin would be able to help you out a little bit better than what I could.

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2013
    Posts
    40

    Re: How to open a webbrowser link in a new tab.

    ok, thanks. dunfiddlin, you have any idea what I can do?

  8. #8
    Junior Member
    Join Date
    Jan 2015
    Posts
    16

    Re: How to open a webbrowser link in a new tab.

    http://www.vbforums.com/showthread.p...pen-in-new-tab


    youve got the same problem as i do
    the problem is that the ahref string is empty because it creates a void(0) in javascript

    how to fix it i'm also searching XD
    Last edited by blackeagle8100; Aug 11th, 2015 at 01:34 PM. Reason: same question

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.