I have loaded an external URL in my WebView. Now what I need is that when the user clicks on the links on the page loaded, it has to work like a normal browser and open the link in the same WebView. But it’s opening the default browser and loading the page there?
I have enabled JavaScript. But still it’s not working. Have I forgotten something?
If you’re using a
WebViewyou’ll have to intercept the clicks yourself if you don’t want the default Android behaviour.You can monitor events in a
WebViewusing aWebViewClient. The method you want isshouldOverrideUrlLoading(). This allows you to perform your own action when a particular URL is selected.You set the
WebViewClientof yourWebViewusing thesetWebViewClient()method.If you look at the
WebViewsample in the SDK there’s an example which does just what you want. It’s as simple as: