从onPageFinished函数的loadURL完成UI更改后,Android Web View不会刷新

时间:2016-09-20 10:48:33

标签: javascript android webview android-webview

public static String abc;
public static WebView webview;
public static String response;
public String urls = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    webview = (WebView) findViewById(R.id.webview);

    webview.addJavascriptInterface(new LoadListener(), "HTMLOUT");
    webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webview.getSettings().setAppCacheEnabled(false);

    webview.setWebViewClient(new WebViewClient() {


        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub


            super.onPageStarted(view, url, favicon);

        }

        @Override
        public void onPageFinished(WebView view, String url) {


            System.out.println(urls);

            urls += " \n" + url;
            try {
                view.loadUrl("javascript: (function() {document.getElementById('mobileNumber').value= '8';}) ();");
                view.loadUrl("javascript: (function(){document.getElementById('fpId').value = 2454344344; })();");
                view.loadUrl("javascript:window.HTMLOUT.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");




            }catch (Exception e){

                System.out.println(e);

在视图对象上执行view.loadUrl后,返回的HTML字符串具有已修改的数据,但在webview中呈现的页面不会更改。 另外,

view.loadUrl("javascript: (function(){document.getElementById('mobileNumber').value= '8';}) ();"); ---- would modify the change successfully in the HTML ( not rendered back to the webview still)

但是:

view.loadUrl("javascript: (function(){document.getElementById('fpId').value = '2454344344'; })();"); ---- would not even change the value field .  

提前致谢。

0 个答案:

没有答案