I had the same problem, and after the following various explanations on stackOverflow, I managed to get my work done.
here is my approach
webView.loadUrl(url); webView.getSettings().setDomStorageEnabled(true); webView.setWebViewClient(new WebViewClient(){ public void onPageFinished(WebView view, String url) { String email="email@email.jp"; //view.loadUrl("javascript:document.getElementById('email').value = '"+email+"'"); view.loadUrl("javascript:document.forms[0].email.value = '"+email+"';"); Log.d("email", "can not add email"); } });
2 things: 1) you need to add this line webView.getSettings().setDomStorageEnabled(true); (reference: Android WebView always returns null for javascript getElementById on loadUrl )
2) you need to access the variable in your php code using this view.loadUrl("javascript:document.forms[0].email.value = '"+email+"';"); as you can see in my code, I used the solution suggested by @gnpaolo, but it didnβt work for me, so I commented on it and took advantage of it. (link: How to insert a row in Android WebView )
Finally, I just want to add that you do not need to create special javascript.
one more thing forms[0] is the position of the variable in the php form, and in my case I have the user's email address, so I wrote view.loadUrl("javascript:document.forms[0].email.value = '"+email+"';");
Hope this can help others.
Edess Elder Jul 03 '15 at 9:05 2015-07-03 09:05
source share