I tried to load the string which contains the alert function, into a webview. The javascript code is working fine in the browser, but when it is executed in emulator, it is not working. Can any one suggest some ideas for the code to be worked. A part of my code which I developed in Android is also added below. Thanks in Advance.
try{
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
String textToHtml= "<html><body><script lang='javascript'>alert('Hello');</script></body></html>";
webview.loadDataWithBaseURL("",textToHtml, "text/html", "utf-8", "");
}catch(Exception e){
Toast.makeText(DROID_HTML.this,e.getMessage(), Toast.LENGTH_SHORT).show();
}