android webView自动填充用户名和密码不起作用

loading...


0

我正在使用webView将用户名和密码传递给活动 . 问题是网址加载成功但我想填写(自动填充)用户名和密码 . 我是初学者,请帮助或给我任何合适的github链接 .

WebSettings webSettings = superWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    superWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {


            view.loadUrl("javascript:document.getElementById('username').value = '"+userName+"';" +
                    "document.getElementById('password').value='"+password+"';");
        }
    });
    superWebView.loadUrl(url);

loading...

2回答

  • 0

    use this webview settings
    htmlWebView.getSettings().setAppCacheEnabled(true); htmlWebView.getSettings().setAppCachePath("/data/data" + getPackageName() + "/cache"); htmlWebView.getSettings().setSaveFormData(true); htmlWebView.getSettings().setDatabaseEnabled(true); htmlWebView.getSettings().setDomStorageEnabled(true); CookieManager.getInstance().acceptCookie();

    用你自己的webview替换htmlWebview


  • 0

    调用javascript作为函数而不是这个 .

    public void onPageFinished(WebView view, String url) {
     view.loadUrl("javascript: (function() {document.getElementById('username').value= '"+userName+"';  document.getElementById('password').value='"+password+"';  }) ();" );
            }
    
评论

暂时没有评论!