|
Control webView when Android comes with access to a URL, the URL will redirect some way, then there will be a problem.
As follows:
You want to open "C URL" in the "A URL", but it is actually open "C URL" when it is required by "B URL" to transit.
It appeared in the following situation:
1
A URL -> B site (redirects to C) -> C Website
Well, look at it now and then some of our habits when using webView.
If we say we do not want to allow users webView click connection, allowing users to open the system browser to navigate, but continue to use our webView browse words.
Our general practice:
webView.setWebViewClient (new WebViewClient () {
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
// Control new connections open in the current WebView
webView.loadUrl (url);
return true;
}
});
Through the above method, so that our browser can continue to access the links page, but the above manner, it met the needs required retreat, there is a problem.
We assume that this time, users need to "C URL" to return to the "A site" users themselves do not know the middle of a "B URL", the presence of users just want to click on my goBack time, we will return to the "A URL "
But look at the above structural formula is: A URL -> B site (redirects to C) -> C web site.
This can be judged directly call webView.goBack () will return to the "B URL", but "B URL" URL function is redirected to the "C URL", so users see a phenomenon that can not be goBack , the CPC goBack, and again return to the "C web site."
The above problem how to solve it?
Modify, override the method above us.
webView.setWebViewClient (new WebViewClient () {
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
return false; // doc comment on is: True if the host application wants to handle the key event itself, otherwise return false (if the program needs to deal with, it returns true, if not addressed, it returns false)
// This place we return false, does not deal with it, give it to webView own process.
}
}); |
|
|
|