|
-
Sep 4th, 2009, 12:26 PM
#1
Thread Starter
Member
[RESOLVED] Find Clicked Url Link/ Open Link In New Tab
Hi All,
Im trying to create a webbrowser in VB 08;
I was wondering how i would create new tab with the Link the clicked.
*EG* They Right-Click Link > Open In New Window/Tab > Makes New Tab In My Program > Navigates To The Linked Clicked.
Is there any possible way of doing this?!
Thanks In Advance,
Jamie.
-
Sep 4th, 2009, 01:46 PM
#2
Addicted Member
Re: Find Clicked Url Link/ Open Link In New Tab
Use a TabControl and when the url is clicked add a new tab and generate a new WebBrowser control in it.
-
Sep 4th, 2009, 06:53 PM
#3
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
 Originally Posted by Gonegaming12
Use a TabControl and when the url is clicked add a new tab and generate a new WebBrowser control in it.
Done That, But How Would I get it to navigate to the link clicked url?
-
Sep 4th, 2009, 07:22 PM
#4
Re: Find Clicked Url Link/ Open Link In New Tab
Set the WebBrowser.Nagivate("siteClicked")
Please mark you thread resolved using the Thread Tools as shown
-
Sep 5th, 2009, 01:07 PM
#5
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
 Originally Posted by danasegarane
Set the WebBrowser.Nagivate("siteClicked")
Thats The thing, How do i get it to find the link they clicked on ? From The Website They was on.
-
Sep 5th, 2009, 04:01 PM
#6
Re: Find Clicked Url Link/ Open Link In New Tab
The webbrowser control raises a number of events when the user tries to do things such as following a hyperlink.
I havent got visual studio open at the moment but if you look at the events it raises you ought to be able to trap the appropriate event and examine the URL it is expecting to navigate to. Just intercept this and get your new browser to navigate to that URL
-
Sep 6th, 2009, 06:28 AM
#7
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
 Originally Posted by keystone_paul
The webbrowser control raises a number of events when the user tries to do things such as following a hyperlink.
I havent got visual studio open at the moment but if you look at the events it raises you ought to be able to trap the appropriate event and examine the URL it is expecting to navigate to. Just intercept this and get your new browser to navigate to that URL
Sorry To be off hassle but i dont know what the event is. and how i would set it out.
-
Sep 6th, 2009, 07:08 AM
#8
Re: Find Clicked Url Link/ Open Link In New Tab
OK the webbrowser control has a "Navigating" event. Like all standard framework events this passes an eventargs object - in this case its a specialised event args object : WebBrowserNavigatingEventArgs, which among other properties it exposes is "URL" telling you where it is about to navigate to.
This event gets fired before the webbrowser control actually starts navigating, so you can put code into this event, trap the URL that it is about to navigate to, create your new tab with a new webbrowser control and navigate that browser to this URL, and cancel navigation on the initial webbrowser.
-
Sep 6th, 2009, 02:31 PM
#9
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
Please could u give me the code ( i cant seem to figure it out ) this is my newWindow Code:
Code:
Dim browse As New WebBrowser
TabControl1.TabPages.Add(i, "Page" & 1)
browse.Name = "wb"
browse.Dock = DockStyle.Fill
TabControl1.SelectTab(i)
TabControl1.SelectedTab.Controls.Add(browse)
i = i + 1
e.Cancel = True
I have got it to cancel the internet explorer to open but cant get/set the url.
-
Sep 6th, 2009, 02:36 PM
#10
Re: Find Clicked Url Link/ Open Link In New Tab
How is this code called? ie is it being called from an event and if so what event?
-
Sep 6th, 2009, 02:37 PM
#11
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
-
Sep 6th, 2009, 03:14 PM
#12
Re: Find Clicked Url Link/ Open Link In New Tab
OK the NewWindow event doesn't reveal the URL so you'd need to get the URL from a different event. Here's an example which grabs the URL you are about to navigate to from the Navigating method and then displays that in the NewWindow Event :
Code:
Public Class Form1
Private _URL As String
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
_URL = e.Url.ToString
End Sub
Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
MessageBox.Show(_URL)
End Sub
End Class
So you ought to be able to combine that code with your own code to use _URL to navigate your new browser.
-
Sep 6th, 2009, 03:20 PM
#13
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
would this by any chance work:
Code:
Dim i As Integer = 1
Public _URL As String
Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
_URL = e.Url.ToString
End Sub
Public Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
Dim browse As New WebBrowser
TabControl1.TabPages.Add(i, "Page" & 1)
browse.Name = "wb"
browse.Dock = DockStyle.Fill
browse.ScriptErrorsSuppressed = True
TabControl1.SelectTab(i)
TabControl1.SelectedTab.Controls.Add(browse)
e.Cancel = True
AddHandler WebBrowser1.Navigating, AddressOf WebBrowser1_Navigating
AddHandler WebBrowser1.DocumentCompleted, AddressOf browse_done
browse.Navigate(_URL)
i = i + 1
End Sub
-
Sep 6th, 2009, 03:27 PM
#14
Re: Find Clicked Url Link/ Open Link In New Tab
Looks good at first glance but the best way to find out is to try it...
(NB not sure why you've made _URL public - if you want to expose it as a property you should give it a "proper" name such as URL)
-
Sep 6th, 2009, 03:28 PM
#15
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
For some reason it doesnt. it just displays a white page.
-
Sep 6th, 2009, 03:33 PM
#16
Re: Find Clicked Url Link/ Open Link In New Tab
 Originally Posted by Jamie2993
For some reason it doesnt. it just displays a white page.
OK a couple of things.
I'd put a breakpoint on the line browse.navigate(_URL) and check that a) the line is being run and b) check what _URL evaluates to.
EDIT - also, when you are adding handlers you don't seem to he adding to the new browser control.
-
Sep 6th, 2009, 03:42 PM
#17
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
right it does get the link + what do u mean adding to the new browser control?
-
Sep 6th, 2009, 03:46 PM
#18
Re: Find Clicked Url Link/ Open Link In New Tab
You are creating a new browser control with this line
Code:
Dim browse As New WebBrowser
These two lines are adding event handlers dynamically
Code:
AddHandler WebBrowser1.Navigating, AddressOf WebBrowser1_Navigating
AddHandler WebBrowser1.DocumentCompleted, AddressOf browse_done
Which is all well and good, but you are adding event handlers to WebBrowser1 (which I'm guessing is the default webbrowser on the 1st tab?) and not your new webbrowser. If you want to add the handlers to your new WebBrowser then I'd expect it to be
Code:
AddHandler browse.Navigating, AddressOf WebBrowser1_Navigating
AddHandler browse.DocumentCompleted, AddressOf browse_done
-
Sep 6th, 2009, 03:47 PM
#19
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
-
Sep 6th, 2009, 03:50 PM
#20
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
right that does work but when u try do that on the tab u just made it just open it in Internet explorer.
-
Sep 6th, 2009, 03:55 PM
#21
Re: Find Clicked Url Link/ Open Link In New Tab
OK... lets take a step back...
how does the user activate this functionality? when they right-click on a link are you implementing your own popup menu or are you using the browser's built in popup menu?
-
Sep 6th, 2009, 03:56 PM
#22
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
the built in one. + thats extremly weird, i havent changed nothing and its stopped working
-
Sep 6th, 2009, 03:59 PM
#23
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
ok well im off to bed, due to me having work in the morning, but please could u help as much as possible while im gone.
-
Sep 6th, 2009, 04:00 PM
#24
Re: Find Clicked Url Link/ Open Link In New Tab
 Originally Posted by Jamie2993
the built in one. + thats extremly weird, i havent changed nothing and its stopped working
Does the initial browser (the one created at design time) work differently from the new (dynamically created) one?
-
Sep 6th, 2009, 04:01 PM
#25
Re: Find Clicked Url Link/ Open Link In New Tab
 Originally Posted by Jamie2993
ok well im off to bed, due to me having work in the morning, but please could u help as much as possible while im gone.
Fraid not - I too have work in the morning (and a 100 mile trip to get to work) - while I'm happy to help you identify where your code isn't workign, I'm not going to spend the night beavering away at your problem while you snooze!
-
Sep 10th, 2009, 10:29 AM
#26
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
well im finally back lol, lets get this thread showing again
-
Sep 10th, 2009, 11:17 AM
#27
Thread Starter
Member
Re: Find Clicked Url Link/ Open Link In New Tab
right ive got it to add a new tab + navigate to A url but the url is the tab u just selected the link from
E.G on tab at a page for a google search "visual basic" u right-click on a link > new window > it will navigate to the google search page.
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
|