I implement the many things using the webViewClient like onUnhandledKeyEvent,shouldOverrideUrlLoading and more.If want to add the support for alertbox then need to switch to WebChromeClient then i can not do other things.Any one know how mix the both future?
I have check the code for javasript alert box at http://lexandera.com/2009/01/adding-alert-support-to-a-webview/
Thank you
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.
Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.
Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.
You need to set WebChromeClient(This handles JavaScript dialogs, favicons, titles, and the progress) for your WebView .
WebView wView = new WebView(this){
@Override
public boolean onJsAlert(WebView view, String url, String message,
JsResult result) {
// TODO Auto-generated method stub
Log.i("my log","Alert box popped");
return super.onJsAlert(view, url, message, result);
}
};
setContentView(wView);
wView.getSettings().setJavaScriptEnabled(true);
WebChromeClient cClient = new WebChromeClient();
wView.setWebChromeClient(cClient);
wView.loadUrl("file:///android_asset/" + yourHtmlFile);
Hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With