使用 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;