3

I am trying to set the value of a global variable from Android code.

               mWebView.loadUrl("javascript:(function() { " +  
                       "loginID = '"+nicu_app.urlSelected+"'; " +  
                       "})()");  

but when I load the webpage in a webview and check to see if this variable has been set by the Android code, I don't see any positive results.

Any help will be appreciated.

Thanks, Sana.

1
  • have you defined a javascript interface? Commented Jul 26, 2010 at 19:39

2 Answers 2

4

I would recommend using addJavascriptInterface to create a proxy between Java and the webview Javascript

Sign up to request clarification or add additional context in comments.

Comments

1

Yes I was able to set the javascript variable, which was declared global in the HTML-Javascript page and then use the

mWebView.loadUrl("javascript:(function () { " +
                           "setVariable("+valueToSetInHtmlPage+");" +
                           "})()");

and at the HTML webpage I had

function setVariables(a,b) {
    loginID = a; 
    serverUrl = b;
}

where loginID and serverUrl are both global

Comments

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.