My favorites | Sign in
Project Home Issues
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 752: JavaScript alert() calls do not execute in WebView
14 people starred this issue and may be notified of changes. Back to list
Status:  Declined
Owner:  ----
Closed:  Jul 2009

Sign in to add a comment
Reported by, Jun 18, 2008
The following code does nothing in a WebView.

alert("display this text");

The WebView instance was created like this...

startPage = "";
webView = (WebView) findViewById(;
Jun 18, 2008
More problems are seen when the html is loaded from the file system.
startPage = file:///android_asset/wvtest.html
Jun 18, 2008
Also, images do not always display when the page is first loaded and the image is 
inserted dynamically using javascript and innerHTML.

See attached html file.
533 bytes   View   Download
Jul 8, 2008
I'm not sure your syntax is correct, I don't think a html file can loaded from either
URL you provide above. Have you tried to push your wvtest.html to the /sdcard
directory on the emulator, and load it from there?
Status: NeedsInfo
Cc: Brett.Chabot
Jul 12, 2008
The html does load and execute just fine.  There is other JavaScript in the html 
file that is execute but all the alert statements are not executed.  No alert dialog 
appears.  It seems like the JavaScript engines is ignoring them or it does have a 
handle to the window so it can't create the dialog.

The IP address if for localhost.  This must be used with the emulator since 
the emulator uses itself.  If you run a local webserver you can hit it 
with this code easily and load an html file yourself to try it out.
Dec 23, 2008
I can comfirm this issue - just experienced the same problem, googled it and ended up
Feb 5, 2009
(No comment was entered for this change.)
Status: New
Mar 1, 2009
I can confirm this issue as well.
Javascript alert() windows do not popup from a webview.
May 21, 2009
i am also facing the same thing . its not popping up alert 
May 23, 2009
I had this issue too with xcode Simulator iPhone OS 2.1.  I installed v2.2.1, and it
works now.
Jul 23, 2009
You must provide a chrome client that can handle alerts:

Status: Declined
May 9, 2010
(No comment was entered for this change.)
Cc: -Brett.Chabot
Jan 19, 2011
One should use a WebChromeClient to get these alerts and the functionality can be overwritten using the onJsAlert() method. Hope this helps!

WebView wv=new WebView(this);	
wv.setWebChromeClient(new WebChromeClient() {
	public boolean onJsAlert(WebView view, String url, String message,           JsResult result) {
                //Required functionality here
                return super.onJsAlert(view, url, message, result);
Apr 5, 2011
Above event worked but, it does not call on first alert call, next all the alert calls works perfectly.. Is there any work around this issue?
Jun 13, 2011
yupppi...i have dont it with setWebChrmeClient...thank u
Dec 9, 2011
I have same issue that javascript is not working in android device. even for alert function. I have added that in body to fire onload page. but it didnt display anything. what exactly have to do in The WebView instance or WebChrmeClient. Please any one can explain?
Dec 13, 2011
@comment 15 : see the comment 12 (

add this code in the onCreate of your WebViewActivity. This will solve your problem.
Dec 30, 2012
I don't get it. Why do we need to override the onJsAlert() function to execute the DEFAULT behavior? :s  I mean shouldn't Android be handling all the default behaviors itself?
Mar 21, 2013
You don't need to override the onJsAlert() function.
You need to supply a WebChromeClient(), the default one will do, i.e.

WebView wv = new WebView(this);	
wv.setWebChromeClient(new WebChromeClient());

Apr 9, 2013
thnkyou  very much ..i got the solution...:-)
Dec 10, 2013
I have used the following code to make javascript alert in webview.
WebView wv = new WebView(this);	
wv.setWebChromeClient(new WebChromeClient());

The issue with above is when the javascript alert shown on webview ,once the user press home button ,then if i tried to open the application second time the webview is not displaying. any idea?
Jun 26, 2014
Thank u @squan its works well........ :-)
Sign in to add a comment

Powered by Google Project Hosting