Surfing All Website And All Links Opens In Same Webview
when I create webview application to view any website on same webview not browser it works fine but when I click on any link in that website it opens in browser ? how to load all i
Solution 1:
Java version:
You only need to set a WebViewClient
for your WebView
and then all links will be opened it the same WebView
:
webView.setWebViewClient(newWebViewClient());
Solution 2:
privateclassmyCustomWebViewClientextendsWebViewClient {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
//here load the url in your webview
webview.loadUrl(url);
returntrue;
}
And this for set in your webview
webView.setWebViewClient(newmyCustomWebViewClient());
Solution 3:
Solution 4:
You should add a webViewClient of your own.
WebViewmyWebView= (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(newMyWebViewClient());
in the webViewClient you can override the shouldOverrideUrlLoading() method to be like:
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.example.com")) {
// This is my web site, so do not override; let my WebView load the pagereturnfalse;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLsIntent intent = newIntent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
returntrue;
}
I hope you find it helpful.
Post a Comment for "Surfing All Website And All Links Opens In Same Webview"