WebView obtains the url of the link and loads the processed HTML

Source: Internet
Author: User

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])";

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.