表单提交后,WebView 未加载页面 [英] WebView not loading page, after form submit

查看:38
本文介绍了表单提交后,WebView 未加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望通过 WebView 组件解决我在 React Native 中遇到的问题 link,我在android中做了一个直接测试,在尝试加载特定页面时获得相同的错误.

Looking to solve a problem that I have with React Native with the component of WebView link, I did a direct test in android obtaining the same error when trying to load a specific page.

第一页有表单,但输入用户数据提交后,不显示下一页,只显示正在加载..."的信息

The first page contains a form, but after entering the user data and submitting, it does not show the next page, it only shows a message of "Loading ..."

这是我的安卓代码:

public class WebViewActivity extends Activity {

private WebView webView;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview_main);

    webView = (WebView) findViewById(R.id.webView1);
    webView.clearCache(true);
    webView.setWebViewClient(new WebViewClient());
    webView .getSettings().setJavaScriptEnabled(true);
    webView .getSettings().setDomStorageEnabled(true);
    webView.loadUrl("https://auth.mercadopago.com.ve/authorization?client_id=6012820321480442&response_type=code&platform_id=mp&redirect_uri=https%3A%2F%2Fus-central1-quicpyapp.cloudfunctions.net%2FmercadoPagoConnect%3FuserId%3DcljvLoUJNoOHfe636ofMHduXu2o2");

}

}

如果我对以下行进行评论,我还能够观察到该页面正常工作:

I have also been able to observe that the page works correctly if I comment the following line:

//webView.setWebViewClient(new WebViewClient());

测试用户数据如下:"user": "TETE5691798", "password": "qtest6094"

The test user data are as follows:"user": "TETE5691798", "password": "qatest6094"

任何帮助将不胜感激.

推荐答案

试试这个解决方案:

var currentUrl = "google.com" 
var partOfUrl = currentUrl.substring(0, currentUrl.length-2)

webView.setWebViewClient(object: WebViewClient() {

 override fun onLoadResource(WebView view, String url) {
 //call loadUrl() method  here 
 // also check if url contains partOfUrl, if not load it differently.
 if(url.contains(partOfUrl, true)) {
     //it should work if you reach inside this if scope.
 } else if(!(currentUrl.startWith("w", true))) {
     webView.loadurl("www.$currentUrl")

 } else if(!(currentUrl.startWith("h", true))) {
     webView.loadurl("https://$currentUrl")

 } else { 
  //...
 }


 }

 override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) {
// you can call again loadUrl from here too if there is any error.
}
//You should also override other override method for error such as onReceiveError to see how all these methods are called one after another and how they behave while debugging with break point. 
} 

这篇关于表单提交后,WebView 未加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆