Reputation: 67
I wrote a piece of code about JS:
NSString *function1 = @"function getString(){return \"123\";}";
NSString *str = [theWebView stringByEvaluatingJavaScriptFromString:function1];
NSLog(@"str: %@", str);
but the "str" is not equal to "123", the result was
str:
Any help is appreciated。
Upvotes: 0
Views: 2991
Reputation: 539765
Your JavaScript code only defines the function getString
, but never calls
the function. Therefore the result of evaluating the script is empty.
If you actually call the function in the JavaScript
NSString *function1 = @"function getString() {return \"123\";} getString()";
you will get the expected result.
Upvotes: 4