javascript - Setting innerHTML in a webview replaces the entire document instead of just the element -
note: scaloid, syntax bit different java, classes usual android classes java.
i'm initializing webview using:
webview.settings.setjavascriptenabled(true) webview.setwebchromeclient(new webchromeclient)
and call
val jsurl = "javascript:document.getelementbyid('" + gettagid(word) + "').innerhtml = '" + guess + "'" webview.loadurl(jsurl)
where gettagid(word)
existing id (i've debugged this) , guess
short string "abc"
.
it works in desktop browser, in webview replaces entire document instead of replacing element.
i've tried debug , make sure element found replacing call with
"javascript:alert(document.getelementbyid('" + gettagid(word) + "').innerhtml)"
and shows alert right content! replacement goes wrong.
this bug driving me crazy :-( missing?
p.s. i'm working on open-source project: https://github.com/ilyakogan/gluckentext
i still don't know why didn't work, ended adding js function , calling native android code, instead of calling getelementbyid
directly native code.
i added html:
<script> function marksolved(id) { document.getelementbyid(id).classname='solved'; } </script>
and wrote in native code (scala in case, java in general case):
val jsurl = "javascript:marksolved(" + gettagid(answeredword) + ")" webview.loadurl(jsurl)
Comments
Post a Comment