0

I have the following javascript:

public String jscode() {
String myString = "javascript:function myscript() {" +
"     var _$b = window._$b= { version: \"1.0\"};" +
"     _$b.navigate = function(url, title) {" +
                "     rpc.exec(" +// JSON-RPC 2.0
                "              {method: \"navigate\", " +
                "      params: {" +
                "              \"url\": url," +
                "              \"title\": title" +
                "              }});" +
                "       local_url = url;" +

                "      };" +
                "};"


    return myString;

}

Now I am using it in webview onpagefinished such that:

String newString = jscode();
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                            view.evaluateJavascript(newString, null);
                            view.evaluateJavascript("myscript();", null);


                        }

How do I pass the value of "navigate" parameter local_url into the evaluatejavascript function? I looked online for a couple of tutorials but none of them seemed to work. Any ideas?

1 Answers1

0

I think you need to pass arguments to the url you are opening in the webview. If that is the case, try using Uri.Builder class to append the parameters to the url you pass to the webview.

Uri.Builder builder = new Uri.Builder() .appendQueryParameter("param1", value1) .appendQueryParameter("param2", value2); final String params = builder.build().getEncodedQuery(); web_view.loadUrl("your url" + params);

Hope it helps!