Daddy
Daddy

Reputation: 9035

iPhone UIWebView stringFromJavaScript with jQuery

I'm looking for a way to include the jQuery javascript library in my project so I can use

[myWebView stringByEvaluatingJavaScriptFromString:a jquery command];

This doesn't work:

NSString *jQueryPath = [[NSBundle mainBundle]pathForResource:@"jquery-1.4.1" ofType:@"js"];
NSData *jQueryData = [[NSData alloc] initWithContentsOfFile:jQueryPath];
jQuery = [[NSMutableString alloc] initWithData:jQueryData encoding:NSUTF8StringEncoding];
NSString *javaScript = [jQuery stringByAppendingString:@"$('#ct100_mainContent_hypEmbGamerTag img').attr('src');"];
NSString *returnValue = [theWebView stringByEvaluatingJavaScriptFromString:javaScript];

I think it has something to do with the way Objective-C handles the / character.

Any suggestions?

Upvotes: 3

Views: 1363

Answers (1)

Toby Wilson
Toby Wilson

Reputation: 1507

A bit late coming I know, but the easiest way would be to include the jQuery library via a tag on the page if possible.

I'm having problems with the ajax calls screwing up sometimes after user interactions on the UIWebView though.

Upvotes: 1

Related Questions