DrewNaylor / DrewNaylor/DrewWebBrowser

Allow links to be opened in a new tab. (link to code provided.)

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Visual Basic
Stars
5
Forks
2
PR merge metrics
No merged PRs in 30d

Description

I don't know if this will be easy to do considering the things IE already provides in the context menu, but putting this button in the context menu will require me to make one.

https://social.msdn.microsoft.com/Forums/en-US/4204c991-b15e-4968-a37a-392251808ca8/vs-2010-opening-links-in-a-new-tab-code-for-a-tabbed-web-browser?forum=vblanguage

```
Hi,

Here is my walkthrough how to open links in new tab within webbrowser control.

1- Place and dock tabcontrol on your form.

2- Place and dock a webbrowser control inside tab control's tabpage1. Make Webbrowser's name "mywb" which is on tabpage1.

3- Set Webbrowser's IsWebBrowserContextMenuEnabled to False.

4- Add a ContextMenuStrip control on your form which will be added named "ContextMenuStrip1" , then in Webbrowser control's properties set this ContextMenuStrip1 as WebBrowser control's ContextMenuStrip.

5- Add item to ContextMenuStript like "Open In New Tab" , then finally, handle OpenInNewTabToolStripMenuItem 's Click event by double clicking "Open In New Tab" Item that is in your ContextMenuStript control like this:
```
``` vb.net
Private Sub OpenInNewTabToolStripMenuItem_Click _
(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles OpenInNewTabToolStripMenuItem.Click
' create a new webbrowser instance on new tab
Dim wb As New WebBrowser
wb.Name = "mywb"
wb.Url = _
New Uri(DirectCast(Me.TabControl1.SelectedTab.Controls("mywb"), _ WebBrowser).Document.ActiveElement.GetAttribute("href"))
wb.Dock = DockStyle.Fill
' re associate contextmenustrip for each webbrowser instance
wb.ContextMenuStrip = Me.ContextMenuStrip1
wb.IsWebBrowserContextMenuEnabled = False
Dim tabpage As New TabPage("This is New Tab")
tabpage.Controls.Add(wb)
Me.TabControl1.TabPages.Add(tabpage)

End Sub
```
```
Tested the code which i've written, runs fine.

Hope this helps.

Saygılarımla, Onur Güzel
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.