Saturday, June 1, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  6] [ 5]  / answers: 1 / hits: 37342  / 11 Years ago, sat, may 11, 2013, 12:00:00

I am Developing an app with webview but I don't know how to enable JavaScript to show alert dialog in webview.



I ever tried this one but it's isn't work for me.
firstly,I made webview and websettings object
then set following parameters.



    webSettings.setJavaScriptEnabled(true);

webSettings.setBuiltInZoomControls(true);

mWebView.requestFocusFromTouch();

More From » android

 Answers
37

As Per Your Code i thought you don't set following setting Webviewclient and Webcromeclient to enable Javascript in Webview.



 mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient());


Then you load your Html page with following code.



 mWebView.loadUrl(file:///android_asset/+Your_Html_Page);


And This is Html part in your Webview.



<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert(Hello! I am an alert box!);
}
</script>
</head>
<body>

<input type=button onclick=myFunction() value=Show alert box />
</body>
</html>


try this might be helpful.


[#78296] Thursday, May 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mariselas

Total Points: 711
Total Questions: 117
Total Answers: 110

Location: Burkina Faso
Member since Thu, Dec 23, 2021
2 Years ago
;