{"id":2510,"date":"2016-02-10T16:46:15","date_gmt":"2016-02-10T15:46:15","guid":{"rendered":"http:\/\/www.cadetill.com\/?p=2510"},"modified":"2016-02-15T11:45:52","modified_gmt":"2016-02-15T10:45:52","slug":"twebbrowserex-class","status":"publish","type":"post","link":"https:\/\/www.cadetill.com\/en\/twebbrowserex-class\/","title":{"rendered":"TWebBrowserEx Class"},"content":{"rendered":"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.<\/p>\n<p>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).<\/p>\n<p>The TWebBrowserEx class inherits from TWebBrowser directly (so that will be compatible with all applications developed with this component) adding some nice improvements:<!--more--><\/p>\n<ul>\n<li>procedure CallJS: this method does a call to a JavaScript function (with or without params).<\/li>\n<li>procedure EvaluateJavaScript: this method execute JavaScript code.<\/li>\n<li>procedure LoadFromStrings: shows the HTML code passed by a string parameter.<\/li>\n<li>function GetTagValue: function that return the value of any HTML tag.<\/li>\n<\/ul>\n<p>While it is true that we have in Seattle 10 EvaluateJavaScript method from WebBrowser, it isn&#8217;t in previous versions and, also we don&#8217;t have a standard way to access to the HTML elements.<\/p>\n<p>Here are some snippets of code to run this class (isn&#8217;t difficult transform it to a component):<\/p>\n<pre class=\"brush:delphi\">  \/\/ creation of object\r\n  FWebBrowser := TWebBrowserEx.Create(Self);\r\n  FWebBrowser.Parent := Panel2;\r\n  FWebBrowser.Align := TAlignLayout.Client;\r\n\r\n  \/\/ load an url\r\n  FWebBrowser.URL := 'http:\/\/www.cadetill.com\/un-repaso-a-lo-nuevo-de-delphi-10-seattle\/';\r\n\r\n  \/\/ put a html code directly\r\n  FWebBrowser.LoadFromStrings('Hello WebBrowser!', '');\r\n\r\n  \/\/ execute a JavaScript code\r\n  FWebBrowser.EvaluateJavaScript('alert(\"EvaluateJavaScript method from WebBrowserEx class!\")');\r\n\r\n  \/\/ getting a value from id\r\n  lat := FWebBrowser.GetTagValue('lat', 'value');\r\n  lng := FWebBrowser.GetTagValue('lat', 'value');\r\n  ShowMessage(Format('lat\/lng clicked: %s\/%s', [lat, lng]));\r\n\r\n  \/\/ execute a JavaScript function into HTML code\r\n  FWebBrowser.CallJS('MapSetCenter', ['42.51968735985934', '42.51968735985934']);\r\n<\/pre>\n<p>In addition, TWebBrowserEx is open source and is hosted on <a href=\"https:\/\/github.com\/freeonterminate\/delphi\/tree\/master\/TWebBrowser\" target=\"_blank\">github<\/a>.<\/p>\n<p>You can download a demo from this <a href=\"http:\/\/www.cadetill.com\/files\/twebbrowserex.zip\">link<\/a>.<\/p>\n<p>See you!","protected":false},"excerpt":{"rendered":"<p>Sorry, this entry is only available in Espa\u00f1ol.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[34,78],"class_list":["post-2510","post","type-post","status-publish","format-standard","hentry","category-delphi","tag-gmlib","tag-twebbrowserex","category-5-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p13r0p-Eu","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/posts\/2510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/comments?post=2510"}],"version-history":[{"count":7,"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/posts\/2510\/revisions"}],"predecessor-version":[{"id":2517,"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/posts\/2510\/revisions\/2517"}],"wp:attachment":[{"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/media?parent=2510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/categories?post=2510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cadetill.com\/en\/wp-json\/wp\/v2\/tags?post=2510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}