3

Possible Duplicate:
JavaScript alert not working in Android WebView

I am developing an app in which i have to use java script but i am unable to get desired results . My java code is as follows:

 myWebView = (WebView) findViewById(R.id.webview);
            myWebView.loadUrl("file:///android_asset/neww.html");

            WebSettings webSettings = myWebView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            webSettings.setJavaScriptCanOpenWindowsAutomatically(true);

//          myWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");

My html code is as follows:

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
        function show_alert( ){ 
            alert("I am an alert box!");
        }
        </script> 
    </head>
<body>
    <input type="button" onclick="show_alert()" value="Show alert box" />
</body>
 </html>

When the app starts, this page gets displayed...:

when the app loads this page is displayed

...and when i click on show alert box it shows nothing and the following screen appears:

and when i click on show alert box it shows nothing and the following screen appears

Community
  • 1
  • 1

2 Answers2

0

You have a syntax error in your script block. Change show_alert( to show_alert() on line 5 of your HTML page and it should function.

Hal
  • 981
  • 1
  • 9
  • 22
0
     function show_alert( )

here it seems extra space is given between "(" and ")". try this

       function show_alert()

May be it will solve.

Saifuddin Sarker
  • 853
  • 3
  • 8
  • 26