Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference, value given in /home/cadetill/domains/cadetill.com/public_html/wp-includes/class-wp-hook.php on line 286
TWebBrowserEx Class – El blog de cadetill
Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference, value given in /home/cadetill/domains/cadetill.com/public_html/wp-includes/class-wp-hook.php on line 286
Feb 102016
 

Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference, value given in /home/cadetill/domains/cadetill.com/public_html/wp-includes/class-wp-hook.php on line 286

Searching info for GMLib library about news from TWebBrowser in Android and iOS in new version of RAD Studio (HTML access and JavaScript function execution), I have found the TWebBrowserEx class that does all that I need.

This class created by Jun HOSOKAWA is compatible with RAD Studio (from XE5 version -with minor changes- until Seattle 10) and with Appmethod (from 1.14 to 1.17).

The TWebBrowserEx class inherits from TWebBrowser directly (so that will be compatible with all applications developed with this component) adding some nice improvements:

  • procedure CallJS: this method does a call to a JavaScript function (with or without params).
  • procedure EvaluateJavaScript: this method execute JavaScript code.
  • procedure LoadFromStrings: shows the HTML code passed by a string parameter.
  • function GetTagValue: function that return the value of any HTML tag.

While it is true that we have in Seattle 10 EvaluateJavaScript method from WebBrowser, it isn’t in previous versions and, also we don’t have a standard way to access to the HTML elements.

Here are some snippets of code to run this class (isn’t difficult transform it to a component):

  // creation of object
  FWebBrowser := TWebBrowserEx.Create(Self);
  FWebBrowser.Parent := Panel2;
  FWebBrowser.Align := TAlignLayout.Client;

  // load an url
  FWebBrowser.URL := 'http://www.cadetill.com/un-repaso-a-lo-nuevo-de-delphi-10-seattle/';

  // put a html code directly
  FWebBrowser.LoadFromStrings('Hello WebBrowser!', '');

  // execute a JavaScript code
  FWebBrowser.EvaluateJavaScript('alert("EvaluateJavaScript method from WebBrowserEx class!")');

  // getting a value from id
  lat := FWebBrowser.GetTagValue('lat', 'value');
  lng := FWebBrowser.GetTagValue('lat', 'value');
  ShowMessage(Format('lat/lng clicked: %s/%s', [lat, lng]));

  // execute a JavaScript function into HTML code
  FWebBrowser.CallJS('MapSetCenter', ['42.51968735985934', '42.51968735985934']);

In addition, TWebBrowserEx is open source and is hosted on github.

You can download a demo from this link.

See you!

  5 Responses to “TWebBrowserEx Class”

  1. Hello,

    Tdcef3 is now compatible with both VCL and FMX libraries.
    Is it a great amout of work to update your library and use Tdcef3 ?

  2. Hello,
    FWebBrowser.GetTagValue is not work in android platform.
    what to do?

  3. How can I enable javascript in TWebView (WebView) for Delphi Berlin

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.