Web browser is a special container for showing web-content. This is an ideal option for displaying information in a complex format, displaying on-line pages and etc.
Web browser is presented by FGX.WebBrowser.TfgWebBrowser
class in FGX Native.
Loading local HTML page
If you need to create HTML page locally or you would like to load local HTML page from file. You can use TfgWebBrowser.LoadHTML
method.
uses
System.SysUtils, FGX.Application, FGX.Dialogs, FGX.Log;
procedure TForm5.fgFormCreate(Sender: TObject);
var
HTML: TStringList;
begin
HTML := TStringList.Create;
try
HTML.Add('<html>');
HTML.Add('<body>');
HTML.Add('<p style="font-size: 30px; margin-top: 40px">');
HTML.Add('Hello from FGX Native local HTML page!');
HTML.Add('</p>');
HTML.Add('</body>');
HTML.Add('</html>');
fgWebBrowser1.LoadHTML(HTML.Text, 'http://mylocal');
finally
FreeAndNil(HTML);
end;
end;
Tracking URL loading
TfgWebBrowser
supports set of events for tracking stages of loading resources:
OnStartLoading
- specified resource by URL is being start loadingOnFinishLoading
- specified resource by URL is loadedOnErrorLoading
- specified error was occured, when browser loads specified URL.
You can stop loading resource in any time by invoking TfgWebBrowser.StopLoading
method. Also you can reload resource by TfgWebBrowser.Reload
.
Evaluating Javascript
TfgWebBrowser
supports work with Javascript. It can evealuate your Javascript code and return result back to you.
It's a simple code snippet shows getting current document URL via Javascript:
fgWebBrowser1.EvaluateJavaScript('document.URL', procedure (const AResult: string) begin
TfgToast.Show(AResult);
end);
Overriding Url loading
If you want to intercept loading URL, you can use OnDecideLoadUrl
event.
You have an article loaded from a local file with pictures and you want to implement a preview of the images used in the article. You can add links to each images with URL and intercept clicking at this links in OnDecideLoadUrl
event. This event allows decline loading resource by url.
Scroll
Web browser has a set of methods and event for scrolling content.
ScrollBy
- scrolls content on specified offset.ScrollTo
- scrolls content to specified offset.ScrollTop
- scroll content to the beginning.ScrollBottom
- scroll content to the end.ContentSize
- size of loaded content.ContentOffset
- current content offset.