1

When I inject document.getElementsByTagName("body")[0].style.background = "red"; in developers console in firefox, background becomes red. But when I do webview.loadUrl("javascript:document.getElementsByTagName(\"body\")[0].style.background = \"red\";"); in android webview, whole content in it gets replaced by the word "red". Why is background color not changing and content is being replaced? Also, how can I change the style properties in webview using javascript?

1
  • Have you been able to fix this? I have the same problem... Commented Apr 28, 2015 at 8:40

1 Answer 1

2

I solved this problem by injecting the following instead:

webview.loadUrl("javascript:(function() {document.getElementsByTagName(\"body\")[0].style.background = \"red\";})()"); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.