问题
How to make call of Firemonkey code (callback) from JavaScript code in TTMSFMXWebBrowser?
I can perform JavaScript code from Firemonkey, but how I can make a callback or call Firemonkey code/event from JavaScript?
Is it possible?
回答1:
So in the URL you can pass a custom string or whatever data like this:
myurl://dostuff?a=b&c=d
if (Copy(S, 1, 8)='myurl://') then
begin
// now you know it is a callback and not a real URL
// if it is a callback you can cancel the load using the below code
// and then process the callback
end;
TWebBrowser:
procedure TForm2.WebBrowser1ShouldStartLoadWithRequest(ASender: TObject;
const URL: string);
begin
// check URL and
WebBrowser1.Stop;
end;
TTMSFMXWebBrowser:
procedure TForm2.TMSFMXWebBrowser1BeforeNavigate(Sender: TObject;
var Params: TTMSFMXCustomWebBrowserBeforeNavigateParams);
begin
// Get your result from Params.URL and cancel via Params.Cancel := True;
end;
回答2:
You should try Google before you ask ...
Firemonkey WebBrowser is a wrapper and it depends on platform.
Check this example for TWebBrowser on Windows
http://www.delphidabbler.com/articles?article=22&part=1
As WebBrowser is a wrapper, it does not expose all functions. You have to modify it a little for your purposes.
You can also check these topics
Callback Delphi function from TWebBrowser by javascript on Delphi XE6 for all platforms (including iOS, ANDROID)?
http://delphi.radsoft.com.au/2013/11/adding-javascript-processing-capability-to-twebbrowser-in-ios/
来源:https://stackoverflow.com/questions/30046303/callback-from-firemonkey-webbrowser-javascript-code