WebView-将target = _blank链接作为target = _self打开

时间:2018-09-17 14:06:24

标签: android webview

我的应用程序使用Webview加载网站。有些链接的目标是_blank并在新窗口中打开

public class EkChromeViewClient extends android.webkit.WebChromeClient {
    @Override
    public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
        Log.d("!!!new window!!!", "yes");

        WebView newWebView = new WebView(view.getContext());
        newWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
        newWebView.getSettings().setDomStorageEnabled(true);
        newWebView.getSettings().setSupportMultipleWindows(true);
        newWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

        newWebView.setWebViewClient(new EkWebViewClient());

        view.addView(newWebView);
        WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
        transport.setWebView(newWebView);
        resultMsg.sendToTarget();

        return true;
    }

    @Override
    public void onCloseWindow(WebView window) {
        Log.d("!!!close window!!!", "yes");
        super.onCloseWindow(window);
    }
}

但是我只需要在一个窗口中打开所有网址,而忽略target = _blank

1 个答案:

答案 0 :(得分:0)

您需要执行以下操作。

ViewController