UPDATE: If you’re using Delphi XE7, the TWebBrowser component now includes the method EvaluateJavascript (does the same thing as what my GetJavaScript result does), and applies to both iOS and Android.
In a post on the Embarcadero forums some time ago, Charles Vinal asked about whether it would be possible to have TWebBrowser implement the stringByEvaluatingJavaScriptFromString method which is available in UIWebView, which is inherited from its ancestor, UIView.
The short answer is yes, however it requires some modifications to existing source. You need to make copies of FMX.WebBrowser and FMX.WebBrowser.iOS, and put them in the compiler search path. Next, make the following changes – in FMX.WebBrowser, add this to ICustomBrowser:
function GetJavaScriptResult(const ScriptName: string): string;
Next, add this to TCustomWebBrowser:
function TCustomWebBrowser.GetJavaScriptResult(const ScriptName: string): string; begin if Assigned(FWeb) then Result := FWeb.GetJavaScriptResult(ScriptName); end;
(make sure you add the function declaration to the class, too). Next, in FMX.WebBrowser.iOS, add this to TiOSWebBrowserService:
function TiOSWebBrowserService.GetJavaScriptResult(const ScriptName: string): string; begin if Assigned(FWebView) and FWebView.canGoForward then Result := FWebView.stringByEvaluatingJavaScriptFromString(NSSTR(ScriptName)).UTF8String; end;
Note: If your project uses a TTabControl component, you’ll also need to make sure that the source file FMX.TabControl.pas is in your project path.
Now in your project you’ll be able to call the function like this:
var JSResult: string; begin JSResult := WebBrowser1.GetJavaScriptResult('SomeScript'); end;
Hi,
There is same solution in Android?
Thanks
It may be a similar solution; the evaluateJavascript method of the WebView class has been left out of the JWebView interface in Androidapi.JNI.Webkit, so that file would need to be modified to include the method. The help on this method is here. I’m not familiar with how to invoke methods that use the JValueCallback interface; I may be able to look into this later.
hi..
Realties who could figure out how to perform JS in android?
I’ll have a look into that if I have time. I’ve been rather busy with other things..
Or maybe even from a variable to load html?
and maintaining the file reading takes time
Hi , i have a problem.
I modify the FMX.WebBrowser file but aftr this how do you recomplie this component ?
Another question : This modification is compatible with Android ?
It’s not compatible with Android as yet, and you don’t need to recompile the component: just include the altered units in your project directory.
XE 6 – What am I doing wrong?
[DCC Fatal Error] FMX.WebBrowser.pas(452): F2051 Unit FMX.Platform.iOS was compiled with a different version of FMX.WebBrowser.IFMXWBService
I suspect you need to copy FMX.WebBrowser.pas to your project directory, and modify it as per the instructions in the article.
any idea for ask for internet conection. if the mobile dont have internet conection cant enter some area in app!!!??? Embarcadero xe7 multi device
How TWebBrowser permissions are given to use camera and audio?
where are the file FM.Webbrowser to edit ?
FMX.WebBrowser.pas is in the C:\Program Files (x86)\Embarcadero\Studio\xx.x\Source\fmx folder, where xx.x is the version number