Example:
- I navigate to
http://www.stackoverflow.com
with my web browser control - there's a link to FAQ in the top bar, with target
https://stackoverflow.com/faq
- I need to redirect e.g. to the
http://math.stackexchange.com
when I click the FAQ link
The easiest way, as
kobik
suggested is to useTWebBrowser.OnBeforeNavigate2
event. Here is the example.There's another, more complicated method how to achieve the same. It's about using the
IDocHostUIHandler
interface. Except the control of the menus and toolbars visibility, context menu configuration and some events it provides, let's say, the redirect capability.To be more specific, it's the
IDocHostUIHandler.TranslateUrl
method. This method enables the host to modify the URL to be loaded. It exposes the input URL where the web browser control is going to navigate and the output URL where you redirect it, if you want.The following example shows the implementation of the
IDocHostUIHandler.TranslateUrl
method. Please note that I've used the interposed class so if you put this code into your unit, only those web browsers on the form or those created in this unit dynamically will get this behavior.If you click on the Button1 you'll be navigated to the
http://www.stackoverflow.com
and if you click on the FAQ link which is directed to thehttps://stackoverflow.com/faq
you'll be redirected to thehttp://math.stackexchange.com
.