tags:

views:

92

answers:

2

I am using UIWebView to load a url

Inside the page of that url, it uses alert("whatever msg") as javascript

so my UIWebView will pop up a window and show that alert message.

Is there a way to disable this kind of popup window or javascript alert window?

thanks

+1  A: 

Add this after your web view has loaded its content

[MyWebView stringByEvaluatingJavaScriptFromString:@"window.alert=null;"];
pop850
Very helpful, it is working. I have mention that I have to put this message in webViewDidStartLoad delegate method, just for other people who may want to know
Jack
+1  A: 

You can bind window.alert to another function. So:

window.alert = function() {
  //does nothing so effectively "disables" alert
};

Make sure you do this before you call any alerts. The neat thing about this is you can customize the way you display messages to the user. So you could override window.alert to log to the console (for debugging purposes) or you can render it on the page (with a lightbox or something similar).

Vivin Paliath
Yes, this works as well, thanks
Jack
No problem. pop850's answer is probably what you want to accept since it addresses your concern directly.
Vivin Paliath