1

I find that if I use the interface I added before, the webview could not add the javascriptInterface any more. Demo1

    this.webView.loadUrl("http://www.google.com");
    this.webView.addJavascriptInterface(test1, "test1");
    this.webView.addJavascriptInterface(test11, "test11");
    this.webView.addJavascriptInterface(test2, "test2");
    this.webView.addJavascriptInterface(test22, "test22");

    this.webView.loadUrl("javascript:window.test1.describle('Hello1');");
    this.webView.loadUrl("javascript:window.test11.describle('Hello11');");
    this.webView.loadUrl("javascript:window.test2.describle('Hello2');");
    this.webView.loadUrl("javascript:window.test22.describle('Hello22');");

Demo2

    this.webView.loadUrl("http://www.google.com");
    this.webView.addJavascriptInterface(test1, "test1");
    this.webView.loadUrl("javascript:window.test1.describle('Hello1');");
    this.webView.addJavascriptInterface(test11, "test11");
    this.webView.addJavascriptInterface(test2, "test2");
    this.webView.addJavascriptInterface(test22, "test22");

    this.webView.loadUrl("javascript:window.test1.describle('Hello1');");
    this.webView.loadUrl("javascript:window.test11.describle('Hello11');");
    this.webView.loadUrl("javascript:window.test2.describle('Hello2');");
    this.webView.loadUrl("javascript:window.test22.describle('Hello22');");

In the demo2 , when I use the interface such as test11, I will be told that could not find the obj test11

I don't know why. Looking forwards your suggestion

1 Answer 1

5

swap loadUrl and addJavascriptInterface, and might make it.

this.webView.addJavascriptInterface(test1, "test1");
this.webView.addJavascriptInterface(test11, "test11");
this.webView.addJavascriptInterface(test2, "test2");
this.webView.addJavascriptInterface(test22, "test22");
this.webView.loadUrl("http://www.google.com");
Sign up to request clarification or add additional context in comments.

1 Comment

For me it works if I have the loadUrl at the en. It's cruicial however that the interfaces have different naming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.