Vasu Vasu - 1 year ago 193
Javascript Question

How to show android alert dialog in Webview?

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.




Answer Source

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.


And This is Html part in your Webview.

<!DOCTYPE html>
    function myFunction()
        alert("Hello! I am an alert box!");

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

try this might be helpful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download