JS代码:
//根据class名称获取div数组
function getClass(parent,sClass)
{
var aEle=parent.getElementsByTagName('div');
var aResult=[];
var i=0;
for(i0;iaEle.length;i++)
{
if(aEle[i].className==sClass)
{
aResult.push(aEle[i]);
}
};
return aResult;
}
function hideOther()
{
getClass(document,'nav-sides')[0].style.display='none';
getClass(document,'side-bar')[0].style.display='none';
getClass(document,'area-main')[0].style.display='none';
getClass(document,'home-foot')[0].style.display='none';
getClass(document,'enter')[0].style.display='none';
getClass(document,'crumb')[0].style.display='none';
getClass(document,'date-tab clearfix')[0].style.display='none';
document.getElementById('id_sidebar').style.display='none';
document.getElementById('top_nav').style.display='none';
document.getElementById('fix-personal').style.display='none';
document.getElementById('waterlogo').style.display='none';
getClass(document,'wrap')[0].style.minWidth=0;
getClass(document,'game')[0].style.paddingTop=0;
}
然后在WebViewClient的onPageFinished判断url,加载我们的js代码。
然后你的设置webview即可。
@Override
public void onPageFinished(WebView view, String url) {
if(url!=null && url.contains(/p/resource/weapon/iProductID/39)){
String fun=javascript:function getClass(parent,sClass) { var aEle=parent.getElementsByTagName('div'); var aResult=[]; var i=0; for(i0;iaEle.length;i++) { if(aEle[i].className==sClass) { aResult.push(aEle[i]); } }; return aResult; } ;
view.loadUrl(fun);
String fun2=javascript:function hideOther() {getClass(document,'nav-sides')[0].style.display='none'; getClass(document,'side-bar')[0].style.display='none'; getClass(document,'area-main')[0].style.display='none'; getClass(document,'home-foot')[0].style.display='none'; getClass(document,'enter')[0].style.display='none'; getClass(document,'crumb')[0].style.display='none';getClass(document,'date-tab clearfix')[0].style.display='none'; document.getElementById('id_sidebar').style.display='none'; document.getElementById('top_nav').style.display='none'; document.getElementById('fix-personal').style.display='none'; document.getElementById('waterlogo').style.display='none';getClass(document,'wrap')[0].style.minWidth=0;getClass(document,'game')[0].style.paddingTop=0;};
取消
评论