Reputation: 710
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?
Upvotes: 1
Views: 2493
Reputation: 710
I solved this problem by injecting the following instead:
webview.loadUrl("javascript:(function() {document.getElementsByTagName(\"body\")[0].style.background = \"red\";})()");
Upvotes: 2