admin管理员组文章数量:1356704
I have a webview and im loading an external HTML form a site. I try to change the background color using javascript function:
function changeBGC(color){
document.bgColor = color;
}
and that does not work. but if i load locally then im able to change the background color. Is there some kind of security inhibiting me from changing a web page i load into the webview externally ?
I have a webview and im loading an external HTML form a site. I try to change the background color using javascript function:
function changeBGC(color){
document.bgColor = color;
}
and that does not work. but if i load locally then im able to change the background color. Is there some kind of security inhibiting me from changing a web page i load into the webview externally ?
Share Improve this question asked Sep 1, 2013 at 4:15 j2emanuej2emanue 62.6k74 gold badges304 silver badges474 bronze badges 1-
You want t change the background color of Webview ? If yes, then you can try using
setBackgroundcolor
as well. – Shobhit Puri Commented Sep 1, 2013 at 4:31
1 Answer
Reset to default 8You can run javascript using the WebViewClient, example here.
The javascript code that changes the background color of a document.
So to put it all together:
When initing WebView:
WebView webview = new WebView();
webview.setWebViewClient(new WebClient());
webView.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("stackoverflow.");
Your web view client:
public class WebClient extends WebViewClient {
int color;
public WebClient(int color) {
this.color = color;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url)
{
String mand = "javascript:document.body.style.background = " + color + ";";
view.loadUrl(mand);
}
}
本文标签: javascriptAndroidafter loading URL with webview can i change background colorStack Overflow
版权声明:本文标题:javascript - Android - after loading URL with webview can i change background color - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743963462a2569455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论