Home > Web Front-end > HTML Tutorial > webView gets the linked url and loads the processed HTML_html/css_WEB-ITnose

webView gets the linked url and loads the processed HTML_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:47:27
Original
1181 people have browsed it

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);		}	}
Copy after login

The above code is a code snippet of the project. The value of url refers to the above code. Among them, view.loadUrl("javascript:" handleWebViewHeader(url)) in the onPageFinished() function is 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])";


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template