1

I'm working on an iOS app with an UIWebView. The webpage displayed in the UIWebView is working fine when displayed in the Safari app on iOS, but when it is displayed inside an UIWebView nothing happens when tapping the "Sign in" button: http://www.bnpsolutions.com/Common/Login_Mobile.aspx.

Does someone know why?

You can download my small iOS example project here: http://uploads.demaweb.dk/WebView.zip

EDIT1:

I've changed the WebView to display a simple page which just including jQuery: http://uploads.demaweb.dk/WebView2.zip.

The error message is:

WebView[13623:11703] JavaScript exception: (/ajax/libs/jquery/1.7.2/jquery.js):5187 - SYNTAX_ERR - SYNTAX_ERR: DOM Exception 12
Line:
(function(){ 

Why are the UIWebView not able to load jQuery?

Cezar
  • 55,636
  • 19
  • 86
  • 87
dhrm
  • 14,335
  • 34
  • 117
  • 183

3 Answers3

0

I would suggest defining the delegate methods:

– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:
– webView:didFailLoadWithError:    /* especially this one!! */

and put some NSLog traces there so that you can see what is happening. It is possible that Safari is more resilient to errors (or handles it in a friendlier way) than UIWebView, hence the difference in behavior. But you should check it directly in your app...

sergio
  • 68,819
  • 11
  • 102
  • 123
  • I've already done that in my original project. The `webView:didFailLoadWithError:` delegate method is never called. – dhrm May 05 '12 at 10:25
0

Well, using this code to debug your UIWebView i found 2 exceptions in your javascript related to the resource /WebResource.axd. Check that and I hope it result useful.

Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
  • Could you please share your sample project with me? – dhrm May 05 '12 at 16:54
  • @DennisMadsen Humm i just test it, and if jquery is in local, it works, but remotely doesn't – Jonathan Naguin May 09 '12 at 19:06
  • Can you tell me, why this does not work? My client does have a page using jQuery and I need to view that page in my *UIWebView*. – dhrm May 09 '12 at 19:35
  • @DennisMadsen I sorry Dennis, I'm lost with this :( – Jonathan Naguin May 09 '12 at 19:39
  • I've just updated the jQuery test-page. It seems that jQuery loads anyways, since it is able to write jQuery version. I guess jQuery is loaded on my clients site as well. Back to the original question -- I'm still wondering, why nothing happens when tapping the "sign in" button. – dhrm May 09 '12 at 20:55
0

With regards to the error message generated - the UIWebView is indeed able to load jQuery - the message you're getting about the exception (based on the link in the comments about how debugging the UIWebView is hooked up) occurs when the exception is raised - whether the exception is caught or not.

That particular function in jQuery has a try/catch near the beginning of the function that purposefully tries to raise an exception (and catch it).

Try this code to see what I mean:

NSString *htmlString = @"<html><body>Hello World I am a <b>browser</b><script>(function(){try {var a=undefined; a();} catch (err) {} }());</script></body></html>";
[uiWebView loadHTMLString:htmlString baseURL:nil];

Whether the try/catch is there or not, the exception will be reported.

Krease
  • 15,805
  • 8
  • 54
  • 86