在 Delphi 中通过 Android WebView 使用 Window.open 脚本打开弹出窗口

问题描述 投票:0回答:0

使用 android webview 时不会创建弹出窗口

Android WebKit默认不支持,所以在Android Studio中

有覆盖支持的使用示例,所以很容易应用。

我正在做Delphi,但我无法取得进展。

目前使用 Delphi 11.3

我正在努力修复

FMX.WebBrowser.Android.

我必须使用`WebChromeClient',所以要覆盖和测试

type
    TJWebChromeClientEX = class(TJWebChromeClient)
     Public
       dialog :jDialog;
       newWebView :jWebView;
       functiononCreateWindow(view: JWebView; isDialog: Boolean; isUserGesture: Boolean; resultMsg: JMessage): Boolean;  cdecl;
       procedure onCloseWindow(window: JWebView);  cdecl;
     end;
TAndroidWebBrowserService.Create; 

部分

 FWebView.getSettings.setJavaScriptCanOpenWindowsAutomatically(True);
  FWebView.getSettings.setSupportMultipleWindows(TRUE);
  FWebView.setWebChromeClient(TJWebChromeClientEX.Create) ;
procedure TJWebChromeClientEX.onCloseWindow(window: JWebView);
begin
     dialog.dismiss();
    inherited;
end;
function TJWebChromeClientEX.onCreateWindow(view: JWebView; isDialog,isUserGesture: Boolean; resultMsg: JMessage): Boolean;
begin
    newWebview := TjWebView.JavaClass.init(MainActivity);
    newWebview.getSettings().setJavaScriptEnabled(true);
    newWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    newWebview.getSettings().setSupportMultipleWindows(true);
    dialog  := Tjdialog.JavaClass.init(MainActivity);
    dialog.setContentView(newWebview);
    dialog.show();
    newWebview.clearView;
    resultMsg.sendToTarget();
    result :=  TRUE;
    inherited;
end;

android delphi webview popupwindow window.open
© www.soinside.com 2019 - 2024. All rights reserved.