Search code examples
javascriptandroidgoogle-mapstwebbrowserdelphi-xe5

How can I use javascript in TWebBrowser in Delphi XE5 on all platforms (IOS,WIN,ANDROID)?


I want to use TWebBrowser on Android in Delphi XE5 to connect to google maps api. I wrote my own component which works on WIN platform. I used Twebbrowser and IHTMLDocument2. For example :

if Self.Document as IHTMLDocument2<>nil then
  with TWebBrowser(Self).Document as IHTMLDocument2 do
    with ParentWindow do
      execScript(aScript, 'JavaScript');

Is Any chance to run something similar in TWebbrowser on Android (execute javaScript in TWebBrowser)?

Is any other solution?


Solution

  • By the looks of it according to the documentation of the Android WebView, which I currently assume (without having resource to the source) to be behind TWebBrowser, you'd need to pull out the underlying Android WebView and call its add JavascriptInterface() method (documentation here).

    Whether anyone's already done that, I don't know. But that looks to be the requirement. The next step is working out how to access the underlying WebView. I'd imagine that is tucked away in the Android implementation unit for the web browser, so that will be tricky, and may require you to modify the source files.

    Anyway, hopefully that gets you started.