Skip to content

Instantly share code, notes, and snippets.

@jamesjara
Created March 30, 2015 05:54
Show Gist options
  • Save jamesjara/22425c9b6bda0baa8721 to your computer and use it in GitHub Desktop.
Save jamesjara/22425c9b6bda0baa8721 to your computer and use it in GitHub Desktop.
Android inject js or css to external page webview
//---- Appened STYLE
//document.getElementsByTagName('html')[0].innerHTML+='<style>*{color:#fff}</style>'
StringBuilder extraStyles = new StringBuilder();
extraStyles.append("javascript:(function extra(){");
if(getResources().getBoolean(R.bool.extraCss)){
extraStyles.append(
"var aa =document.createElement(\"link\");" +
"aa.type='text/css'; aa.rel='stylesheet'; "+
"aa.href='"+getResources().getString(R.string.extraCssUrl)+"';"+
"document.getElementsByTagName(\"head\")[0].appendChild(aa);"
);
}
if(getResources().getBoolean(R.bool.extraJs)){
extraStyles.append(
"var bb =document.createElement(\"script\");" +
"bb.src='"+getResources().getString(R.string.extraJsUrl)+"';"+
"document.getElementsByTagName(\"head\")[0].appendChild(bb);"
);
}
extraStyles.append("})();");
Log.d("extraextraStyles",extraStyles.toString());
browser.loadUrl(extraStyles.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment