So ive been trying to find the simplest way to append an image in a webview using javascript. i wrote out the html myself and included my own function that looked something like this:
<script type="text/javascript">
function image(src) {
var img = document.createElement("IMG");
img.src = src;
document.getElementById('image').appendChild(img);
}
</script>
I found out that i cant just use
myview.loadurl(javascript:image(‘line1.png’));
So im trying to figure out how i can do this. I was thinking about relegating this function to one line of code i can fit in loadurl(), but i seem to be getting an error around that as well. Ive heard of using addJavascriptInterface but its seems complex and im not sure if it fits what i want. So whats my best course of action?
That is so simple. Try the following
index.html:
and add the following,
To pass more images:
and you pass String array instead of String in load url like
To call image script more times: