如何关闭 javascript 在 android 编程中打开的 webview

how to close a webview which was opened by javascript in android programming

我有一个 android 应用程序,它只包含一个网络视图,我在网络视图中加载了 url(由 .net 使用 javascript 开发),它有facebook 登录,当用户点击那个 facebook 按钮时,它会打开 facebook 对话框,如果用户不想登录,他会点击返回 android 但那个 facebook 对话框仍然出现,如何返回 fom Facebook 对话框到主 Web 视图?

我试过这个代码

 @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (mainWebView.canGoBack()) {
                    mainWebView.goBack();
                    Log.d("webview<---", "going_back");
                } else if (newWebView != null && newWebView.isFocusable()) {
                    FBWebView.removeAllViews();
                    FBWebView.clearHistory();
                    FBWebView.getParent();

                      FBWebView=null;
                    //FBWebView.addView(mWebView);
                    // FBWebView.loadUrl(url);
                    //startActivity(new Intent(MainActivity.this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                    Log.d("fb_webview<---", "finish");

                }
                return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

仍然没有用,任何人都可以建议如何从 fb 对话框返回到主 Web 视图,这里 FBWebview 是在此 activity 中动态创建的,而 mainWebview 是通过 xml 初始化的,如何关闭 fbWebView 以显示 mainwebview?

在 return 语句之前的 KeyEvent.KEYCODE_BACK 情况下编写以下代码:

  /* Closing newly created popup window */
                if (Build.VERSION.SDK_INT < 18) {
                    newWebView.clearView();
                } else {
                    newWebView.loadUrl("about:blank");
                }