Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:01:38+00:00 2026-05-27T18:01:38+00:00

Example: I navigate to http://www.stackoverflow.com with my web browser control there’s a link to

  • 0

Example:

  1. I navigate to http://www.stackoverflow.com with my web browser control
  2. there’s a link to FAQ in the top bar, with target https://stackoverflow.com/faq
  3. I need to redirect e.g. to the http://math.stackexchange.com when I click the FAQ link
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:01:39+00:00Added an answer on May 27, 2026 at 6:01 pm

    The easiest way, as kobik suggested is to use TWebBrowser.OnBeforeNavigate2 event. Here is the example.

    procedure TForm1.WebBrowser1BeforeNavigate2(ASender: TObject;
      const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
      Headers: OleVariant; var Cancel: WordBool);
    begin
      if URL = 'https://stackoverflow.com/faq' then
      begin
        // setting this flag to True will cancel the current navigation
        Cancel := True;
    
        // changing this declared parameter doesn't affect anything
        // I've used it just because it's already declared
        URL := 'http://math.stackexchange.com';
    
        // interrupt all pending navigations and stop dynamic page elements
        (pDisp as IWebBrowser2).Stop;
    
        // and navigate to the target URL
        (pDisp as IWebBrowser2).Navigate2(URL, Flags, TargetFrameName, PostData, Headers);
      end;
    end;
    

    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 the https://stackoverflow.com/faq you’ll be redirected to the http://math.stackexchange.com.

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, SHDocVw, ActiveX, StdCtrls, OleCtrls;
    
    type
      PDocHostUIInfo = ^TDocHostUIInfo;
      TDocHostUIInfo = record
        cbSize: ULONG;
        dwFlags: DWORD;
        dwDoubleClick: DWORD;
    end;
    
    // *********************************************************************//
    // Interface: IDocHostUIHandler
    // Flags:     (0)
    // GUID:      {BD3F23C0-D43E-11CF-893B-00AA00BDCE1A}
    // *********************************************************************//
      IDocHostUIHandler = interface(IUnknown)
        ['{BD3F23C0-D43E-11CF-893B-00AA00BDCE1A}']
        function ShowContextMenu(const dwID: DWORD; const ppt: PPoint;
          const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall;
        function GetHostInfo(var pInfo: TDocHostUIInfo): HRESULT; stdcall;
        function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
          const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
          const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall;
        function HideUI: HRESULT; stdcall;
        function UpdateUI: HRESULT; stdcall;
        function EnableModeless(const fEnable: BOOL): HRESULT; stdcall;
        function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function ResizeBorder(const prcBorder: PRect; const pUIWindow: IOleInPlaceUIWindow;
          const fRameWindow: BOOL): HRESULT; stdcall;
        function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID;
          const nCmdID: DWORD): HRESULT; stdcall;
        function GetOptionKeyPath(var pchKey: POleStr; const dw: DWORD): HRESULT; stdcall;
        function GetDropTarget(const pDropTarget: IDropTarget; out ppDropTarget: IDropTarget): HRESULT; stdcall;
        function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall;
        function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POleStr; var ppchURLOut: POleStr): HRESULT; stdcall;
        function FilterDataObject(const pDO: IDataObject; out ppDORet: IDataObject): HRESULT; stdcall;
      end;
    
      TWebBrowser = class(SHDocVw.TWebBrowser, IDocHostUIHandler)
      private
        function ShowContextMenu(const dwID: DWORD; const ppt: PPoint;
          const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT; stdcall;
        function GetHostInfo(var pInfo: TDocHostUIInfo): HRESULT; stdcall;
        function ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
          const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
          const pDoc: IOleInPlaceUIWindow): HRESULT; stdcall;
        function HideUI: HRESULT; stdcall;
        function UpdateUI: HRESULT; stdcall;
        function EnableModeless(const fEnable: BOOL): HRESULT; stdcall;
        function OnDocWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function OnFrameWindowActivate(const fActivate: BOOL): HRESULT; stdcall;
        function ResizeBorder(const prcBorder: PRect; const pUIWindow: IOleInPlaceUIWindow;
          const fRameWindow: BOOL): HRESULT; stdcall;
        function TranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID;
          const nCmdID: DWORD): HRESULT; stdcall;
        function GetOptionKeyPath(var pchKey: POleStr; const dw: DWORD): HRESULT; stdcall;
        function GetDropTarget(const pDropTarget: IDropTarget; out ppDropTarget: IDropTarget): HRESULT; stdcall;
        function GetExternal(out ppDispatch: IDispatch): HRESULT; stdcall;
        function TranslateUrl(const dwTranslate: DWORD; const pchURLIn: POleStr; var ppchURLOut: POleStr): HRESULT; stdcall;
        function FilterDataObject(const pDO: IDataObject; out ppDORet: IDataObject): HRESULT; stdcall;
      end;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        WebBrowser1: TWebBrowser;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    function TWebBrowser.ShowContextMenu(const dwID: DWORD; const ppt: PPoint;
      const pcmdtReserved: IUnknown; const pdispReserved: IDispatch): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.GetHostInfo(var pInfo: TDocHostUIInfo): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.ShowUI(const dwID: DWORD; const pActiveObject: IOleInPlaceActiveObject;
      const pCommandTarget: IOleCommandTarget; const pFrame: IOleInPlaceFrame;
      const pDoc: IOleInPlaceUIWindow): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.HideUI: HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.UpdateUI: HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.EnableModeless(const fEnable: BOOL): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.OnDocWindowActivate(const fActivate: BOOL): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.OnFrameWindowActivate(const fActivate: BOOL): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.ResizeBorder(const prcBorder: PRect;
      const pUIWindow: IOleInPlaceUIWindow; const fRameWindow: BOOL): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.TranslateAccelerator(const lpMsg: PMSG;
      const pguidCmdGroup: PGUID; const nCmdID: DWORD): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.GetOptionKeyPath(var pchKey: POleStr; const dw: DWORD): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.GetDropTarget(const pDropTarget: IDropTarget;
      out ppDropTarget: IDropTarget): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.GetExternal(out ppDispatch: IDispatch): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    function TWebBrowser.TranslateUrl(const dwTranslate: DWORD;
      const pchURLIn: POleStr; var ppchURLOut: POleStr): HRESULT;
    begin
      // pchURLIn is the URL where the browser is going to navigate
      // ppchURLOut is the URL where the browser will navigate
    
      if pchURLIn = 'https://stackoverflow.com/faq' then
        ppchURLOut := 'http://math.stackexchange.com';
    
      Result := S_OK;
    end;
    
    function TWebBrowser.FilterDataObject(const pDO: IDataObject;
      out ppDORet: IDataObject): HRESULT;
    begin
      Result := E_NOTIMPL;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      WebBrowser1.Navigate('http://www.stackoverflow.com');
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking at a web site we'll call www.example.com . A quick traceroute www.example.com
I am using some custom WebParts in SharePoint like ( http://www.codeplex.com/smartpart ) with some
I had a Drupal installation at www.example.com/test . Now, it's ready to go live,
I'm trying to adapt the following example: http://docs.oracle.com/javase/tutorial/uiswing/examples/zipfiles/components-ScrollDemoProject.zip The purpose of i want to
Let's say I get the source code of some page (e.g. http://example.com ). I
Having a tough time here. please navigate to http://www.cbioportal.org/public-portal/index.do Towards the bottom it says:
I have next link that lets users navigate through a list of URL (stored
The specification of HTML4.01 ( http://www.w3.org/TR/html401/struct/tables.html#adef-summary ) states that the table summary attribute should
I am using the example from the Socket.IO homepage (http://socket.io/). It works and everything,
I have been following this tutorial for setting up tabs in your application. http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.