Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a link from WebBrowser control in default browser?

Status
Not open for further replies.

drdrott

Programmer
Feb 13, 2007
3
BR
On a WebBrowser control (that uses Internet Explorer engine), I need to open the links of the page displayed, on a new window of the default browser, instead of forcing the user to use IE.

I could strip the HTML code to get the URL, put a layer on top of the WebBroser control, to then open the link on the default browser, but this would be lame.

How to do this in a (good) way?
 
Hi and welcome to Tek-Tips. To get the best from these forums read faq222-2244 first.

Do you actually want to use a WebBrowser control (which is of course IE based)? Can you simply shell to the default browser with a Shell to the standard protocol handler. I use a simple function like this:
Code:
Public Function OpenDocument(DocumentWithPath As String) As Long
    OpenDocument = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & DocumentWithPath, vbNormalFocus)
End Function

Then you can call it with
Code:
x = OpenDocument("www.essexsteam.co.uk")

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Hello johnwm,

Thanks for your reply.

In fact, I really need to open a HTML page (that will contain things like ads, links and etc) there, and to open the links (when clicked) on the default browser.

Actually the problem isn't making the app to open a URL in default browser, but to just get the URL of the link that the user clicked on, to then open it on the default browser.

As I said, I though on stripping the HTML code to get the URL, then put a (invisible) layer on top of the WebBrowser control, to open the link on the default browser, but this is lame and will of course have some problems with Flash banners and mapping the page.

What I want is to when the user clicks on something, the app get the URL (not stripping the HTML, because of the Flash problem) and open it on the default browser, and the WebBrowser control to don't open the link itself.

It is possible to do this?
 
Sorry I'm being a bit dense this morning. Are you just trying to capture the user's browsing clicks in their default browser (thus without their knowledge)? It's extremely unlikely that all possible default browsers will exhibit ANY commonality in appearance or programming interface, so I would have thought that your only possible route is to try to monitor traffic at the port level.

If that is not what you want can you maybe clarify?

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
They don't want to capture user clicks in their default browser. Instead they want to capture them in WebBrowser Control in their application which uses the IE engine, and want to open these links in the default browser of the user.

You should investigate the BeforeNavigate2 event which would fire when you click the link. The Url argument contains the new link the browser is navigating to.

Here you can cancel the navigation by setting the Cancel argument to True, and pass the Url to johnwm's OpenDocument function. I did not check the code, but I hope it will work.

Note that this method will not always work. Some links open only from the same session of the browser.

For example, if you are veiwing you email in one browser, it is not possible to copy the link to the inbox and paste in another browser to view it there.
 
Yes Hypetia, this is what I need.

I tried the BeforeNavigate2 event, but it opens the page that is already open on the WebBrowser control (because of the links that opens in a new window).

Same with NewWindow2 event, it just can't get the destination URL.

And I can't change the page to not open links in a new window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top