Webview is an important and commonly used control in android. There are many related contents on the Internet. Here we introduce the relatively rare operations of WebViewClient:
We get the url address of other web pages linked in WebView
private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return true; //返回true才能在当前WebView显示url链接内容,否则会打开其它浏览器 } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); initCollectionImageBtn(url); //1、 view.getOriginalUrl()初始加载为空null,此后该值==view.getUrl() != url // 2、并且url等于onPageFinished的值 imgButtonFresh.setImageDrawable(getResources().getDrawable( R.drawable.selector_nav_to_refresh_stop)); } @Override public void onPageFinished(WebView view, String url) { // view.getOriginalUrl() == view.getUrl() == url if (isCollection) { changeCollectionImgBg(COLLECTION_SATE_AFTER); } else { changeCollectionImgBg(COLLECTION_SATE_BEFORE); } imgButtonFresh.setImageDrawable(getResources().getDrawable( R.drawable.selector_nav_to_refresh)); view.loadUrl("javascript:" + handleWebViewHeader(url)); super.onPageFinished(view, url); } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); } }
"document.body.removeChild(document.getElementsByTagName("header")[0])";
or "document.body.removeChild(document.getElementsByClassName("header")[0])";