WebView obtains the url of the link and loads the processed HTML
Webview is an important and commonly used control of android. It has many related content on the network. Here we will introduce the rare operations of WebViewClient:
We get the url of the webpage linked to WebView.
Private class MyWebViewClient extends WebViewClient {@ Overridepublic boolean shouldOverrideUrlLoading (WebView view, String url) {return true; // return true to display url link content in the current WebView, otherwise, other browsers will be opened} @ Overridepublic void onPageStarted (WebView view, String url, Bitmap favicon) {super. onPageStarted (view, url, favicon); initCollectionImageBtn (url); // 1. view. the initial loading of getOriginalUrl () is null, and then the value = view. getUrl ()! = Url // 2, and the url is equal to the value of onPageFinished imgButtonFresh. setImageDrawable (getResources (). getDrawable (R. drawable. selector_nav_to_refresh_stop);} @ Overridepublic void onPageFinished (WebView view, String url) {// view. getOriginalUrl () = view. getUrl () = urlif (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) ;}@ Overridepublic void onReceivedError (WebView view, int errorCode, String description, String failingUrl) {super. onReceivedError (view, errorCode, description, failingUrl );}}
The above code is a code snippet of the project. For the url value, refer to the above Code. Here, the view in the onPageFinished () function. loadUrl ("javascript:" + handleWebViewHeader (url) is to load the processed HTML page, where the header content is removed:
"Document. body. removeChild (document. getElementsByTagName (\" header \ ") [0])";
Or "document. body. removeChild (document. getElementsByClassName (\" header \ ") [0])";