在webview中访问互联网应用,碰到弹出窗口怎么办?

webview加载了一个页面,页面里点某一个button时候弹出一个确认对话框,这个对话框怎么也不显示如果直接用系统自带的浏览器是可以弹出来的请问是怎么回事?webview加载了一个页面,页面里点某一个button时候弹出一个确认对话框,这个对话框怎么也不显示如果直接用系统自带的浏览器是可以弹出来的

请问是怎么回事?


解决方法:(未经证实)

1。

重载WebChromeClient的onJsConfirm方法

final Context myApp = this;
final class MyWebChromeClient extends WebChromeClient {
    @Override
    public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
        new AlertDialog.Builder(myApp)
        .setTitle("App Titler")
        .setMessage(message)
        .setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                result.confirm();
            }
        })
        .setNegativeButton(android.R.string.cancel,
                new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                result.cancel();
            }
        })
        .create()
        .show();

        return true;
    }
}



2。

重写onCreateWindow即可
@Override
                public boolean onCreateWindow(WebView view, boolean dialog,
                        boolean userGesture, Message resultMsg) {
                    WebView childView = new WebView(getActivity());
                    final WebSettings settings = childView.getSettings();
                    settings.setJavaScriptEnabled(true);
                    childView.setWebChromeClient(this );
                    WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
                    transport.setWebView(childView);
                    resultMsg.sendToTarget();
                    mHadOnCreateWindow = true;
                    return true;
                }

记得要
     final WebSettings settings = mWebView.getSettings();
       settings.setJavaScriptEnabled(true);
       settings.setJavaScriptCanOpenWindowsAutomatically(true);

你可能感兴趣的:(android)