WebView: Activate JavaScript and Open Links Inside

1 vote · 2 comments

This code activates JavaScript for a given WebView, and opens new link inside the WebBiew, not in the Browser.

raw ·
copy
· download
public class WebViewTest extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* Set the Content View */ setContentView(R.layout.main); /* Get the WebView */ WebView wv1 = (WebView) findViewById(R.id.wv1); /* Activate JavaScript */ wv1.getSettings().setJavaScriptEnabled(true); /* Prevent WebView from Opening the Browser */ wv1.setWebViewClient(new InsideWebViewClient()); } /* Class that prevents opening the Browser */ private class InsideWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } }
Add a comment

2 Comments

Hello, thaks for this code. It is something that I need. My question: How may I react to trackball click? I do link with javascript alert and I catch reaction for this on method onJsConfirm. When I touch with my finger on link everithing works good but when I use trackball it opens new browser. Code above solve it but how can I react to javascript Confirm?

Reply · May 22, 2009, 9:42 p.m.

SDGTR23YHT234FD

i'm exceptionally effective [url=http://google.com/]google.com[/url]

Haw are you?

Reply · Oct. 2, 2009, 8:04 a.m.