javascript - How to set the text of the button in the webview? -


i'm working on webview in android, wanted change text of button inside webview.

i tried these line of codes not working

webview.loadurl("javascript:document.getelementbyname('btn').value = 'test';"); 

and this...

string str="test"; webview.loadurl("javascript: setbuttontext(strbtext,str)"); 

here's sample of code

in oncreate set enable javascript , load html

webview=(webview)findviewbyid(r.id.wbview); webview.getsettings().setjavascriptenabled(true); webview.setwebchromeclient(new webchromeclient()); webview.loadurl("file:///android_asset/www/index.html"); 

and here's method want change text of button programmatically

 @override     protected void onresume() {         super.onresume();          if (activity.canreadcardwithcamera()) {             //set text true         } else {             //set text false         } 

index.html

    <!doctype html> <html> <head> <script scr="index.js"></script>  </head> <body> <input id="btn" type="button" value="default" onclick="dosomething();" /> </body> </html>   

index.js

function setbuttontext(strbtext,str){   document.findelementbyid(btn).value=str; } 

why don't try :

webview.loadurl("javascript:setbuttontext('test', 'test')"); 

edit:

also, found bug in setbuttontext() js function. :

function setbuttontext(strbtext,str){   document.getelementbyid("btn").value=str; } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -