1 private void initWebView(String url) { 2 twoCode.loadUrl(url); 3 WebSettings settings = twoCode.getSettings(); 4 settings.setJavaScriptEnabled(true);// 設置支持javascript腳本 5 6 twoCode.setWebViewClient(new WebViewClient() { 7 public boolean shouldOverrideUrlLoading(WebView view, String url) { 8 view.loadUrl(url); 9 return true; 10 } 11 12 @Override 13 public void onPageFinished(WebView view, String url) { 14 super.onPageFinished(view, url); 15 String fun = "javascript:function getClass(parent,mClass)" + 16 "{" + 17 "var aEle=parent.getElementsByTagName('div');" + 18 "var aResult=[];" + 19 "var i=0;" + 20 "for(i<0; i<aEle.length; i++) {" + 21 "if(aEle[i].className==mClass)" + 22 "{" + 23 "aResult.push(aEle[i]);" + 24 "}" + 25 "};" + 26 "return aResult;" + 27 "}"; 28 view.loadUrl(fun); 29 30 String fun2 = "javascript:function hideOther() " + 31 "{" + 32 "getClass(document,'horizontal-padding')[0].style.display='none';" +// 搖一搖或點擊二維碼刷新 33 "getClass(document,'text-right horizontal-padding vertical-margin')[0].style.display='none';" +// 如何開門?獲取幫助 34 "document.getElementById('header').style.display='none';" +// 鎖掌櫃體驗羣 35 "document.getElementById('footer').style.display='none';" +// Copyright ©2014-2016. uclbrt, inc. All Right Reserved. 36 "document.getElementById('roomInfo').style.display='none';" +// 測試樓棟 一層 103 37 "}"; 38 view.loadUrl(fun2); 39 view.loadUrl("javascript:hideOther();"); 40 } 41 }); 42 43 }
js代碼
1 function getClass(parent,mClass) 2 { 3 var aEle=parent.getElementsByTagName('div'); 4 var aResult=[]; 5 var i=0; 6 for(i<0;i<aEle.length;i++) 7 { 8 if(aEle[i].className==mClass) 9 { 10 aResult.push(aEle[i]); 11 } 12 }; 13 return aResult; 14 } 15 16 function hideOther() 17 { 18 getClass(document,'horizontal-padding')[0].style.display='none'; 19 getClass(document,'text-right horizontal-padding vertical-margin')[0].style.display='none'; 20 getClass(document,'advertisementContainer')[0].style.display='none'; 21 getClass(document,'copyright')[0].style.display='none'; 22 document.getElementById('header').style.display='none'; 23 document.getElementById('footer').style.display='none'; 24 document.getElementById('roomInfo').style.display='none'; 25 document.getElementById('actionListContainer').style.display='none'; 26 getClass(document,'modal-body')[0].style.display='none'; 27 getClass(document,'modal fade')[0].style.display='none'; 28 }