Search code examples
delphifiremonkeydelphi-10.1-berlin

Disable scrolling possibility of TWebBrowser


Does anyone know, how to disable scrolling possibility of TWebBrowser control in a Firemonkey iOS / Android application? My goal is to get absolutely static element that will not react on touches and so on.


Solution

  • There is no single setting or action that disables all user actions of the Fmx.TWebBrowser. But there is a feature you can use for your purpose.

    The feature I refer to, is Fmx.WebBrowser.TCustomWebBrowser.CaptureBitmap documented here

    Description

    Captures the currently visible Web page as a bitmap.

    This method returns a TBitmap object, which allows you to create, manipulate and store images in memory or as files on a disk. The scenario of the use of this method could be as follows: 1. Call this method to capture a visible Web page as a bitmap. 2. Hide a TWebBrowser control. 3. Display the bitmap and overlay other components (such as buttons or popups) on top of the bitmap.

    In your case you would just hide the WB and display the bitmap.

    Tested with the following code:

    type
      TForm25 = class(TForm)
        Button1: TButton;
        WebBrowser1: TWebBrowser;
        Edit1: TEdit;
        Image1: TImage;
        Timer1: TTimer;
        procedure Button1Click(Sender: TObject);
        procedure WebBrowser1DidFinishLoad(ASender: TObject);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
        bmp: TBitmap;
      public
        { Public declarations }
      end;
    
    implementation
    
    
    procedure TForm25.Button1Click(Sender: TObject);
    begin
      WebBrowser1.URL := Edit1.Text;
    end;
    
    procedure TForm25.Timer1Timer(Sender: TObject);
    begin
      bmp := WebBrowser1.CaptureBitmap;
      Image1.Bitmap := bmp;
    end;
    
    procedure TForm25.WebBrowser1DidFinishLoad(ASender: TObject);
    begin
      Timer1.Enabled := True;
    end;
    

    enter image description here

    With the WB hidden, it cannot be operated on.

    The timer (1000 ms) I added because my attempts to capture the image already in the OnDidFinishLoad() event did nöt succeed.