Callback from Firemonkey WebBrowser JavaScript code

我怕爱的太早我们不能终老 提交于 2020-02-07 06:44:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!