Callback Delphi function from TWebBrowser by javascript on Delphi XE6 for all platforms (including iOS, ANDROID)?

后端 未结 3 577
轮回少年
轮回少年 2020-12-20 18:03

I need create an application on Delphi XE6 for Android and iOS. This application mest be use a TWebBrowser to show Google Maps, then I need \"send\" from Delphi to javascrip

3条回答
  •  庸人自扰
    2020-12-20 18:26

    The proper way to do it is with the addJavascriptInterface function of the Android WebView, as can be seen here, here and here.

    The Firemonkey TWebBrowser does not expose this function by default.

    There is a custom WebView wrapper control in DPF Android as can be seen here.

    You could modify that control to add the addJavascriptInterface function.

    For TWebBrowser on IOS you could use the custom web browser controls in sourceforge and here.

    Another possible way to do this is with the OnShouldStartLoadWithRequest event of TWebBrowser. You could do something like:

    
    

    or

    
    

    And see if the URL property of OnShouldStartLoadWithRequest contains #param1¶m2¶m3¶m4 or javascript:thisisatest();.

    Basically the idea is to navigate to a URL that doesn't change the URL of the existing page and pick up that URL in the OnShouldStartLoadWithRequest event.

提交回复
热议问题