Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link should be open in same web view in Android

Tags:

android

I am new in Android and I am trying to open a Link in webview using this code

WebView myWebView = (WebView) findViewById(R.id.webinfo);     myWebView.loadUrl("http://oslobokfestival.netteam.no/artical.php?articalid=93");     myWebView.setBackgroundResource(R.drawable.lbg);     myWebView.setBackgroundColor(Color.TRANSPARENT);     myWebView.getSettings().setJavaScriptEnabled(true); 

and in this HTML page contains some links and I want that when user click that link should be open in same webview, at this point its opening in mobile browser, please give me appropriate solution.. Thanks.

like image 210
Mahek Avatar asked Sep 05 '11 13:09

Mahek


People also ask

How do I open a link in WebView?

Within the shouldOverrideUrlLoading() method simply get the URL from the request and pass into the Intent. See the full example.

How to enable JavaScript in WebView in Android?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.


1 Answers

You need to add WebViewClient to your WebView in order to open it in the WebView. Something like

myWebView.setWebViewClient(new WebViewClient() {     @Override     public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {         view.loadUrl(request.getUrl().toString());         return false;     } }); 

like image 184
momo Avatar answered Sep 21 '22 17:09

momo