Example:
- I navigate to
http://www.stackoverflow.comwith 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.comwhen I click the FAQ link
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The easiest way, as
kobiksuggested is to useTWebBrowser.OnBeforeNavigate2event. Here is the example.There’s another, more complicated method how to achieve the same. It’s about using the
IDocHostUIHandlerinterface. 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.TranslateUrlmethod. 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.TranslateUrlmethod. 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.comand if you click on the FAQ link which is directed to thehttps://stackoverflow.com/faqyou’ll be redirected to thehttp://math.stackexchange.com.