hi Marco,

are you waiting for WebView to report load finished before calling javascript?
e.g. see example snippet (loads Google api and calls it):

#import <UIKit/UIKit.h>
@class UIWebView;
@interface WebViewController : UIViewController<UIWebViewDelegate> {}
@property (nonatomic, readonly) UIWebView *webView;
@end

#import "WebViewController.h"
@implementation WebViewController
@dynamic webView;
-(UIWebView *)webView
{
    return (UIWebView *)self.view;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
NSMutableString *htmlCode = [NSMutableString stringWithString:@"<html><head>"]; [htmlCode appendString:@"<script type=\"text/javascript\" src=\"http://www.google.com/jsapi \"></script>"];
    [htmlCode appendString:@"<script type=\"text/javascript\">"];
    [htmlCode appendString:@"google.load(\"language\", \"1\");"];
    [htmlCode appendString:@"</script></head><body></body></html>"];
    [self.webView loadHTMLString:htmlCode baseURL:nil];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *scriptCode = @"google.language.isTranslatable(\"en\")";
NSString *translatable = [webView stringByEvaluatingJavaScriptFromString:scriptCode]; NSLog(@"isTranslatable: %@", (translatable) ? translatable : @"error");
}
@end


regards,
Peter Blazejewicz

On Jan 31, 2009, at 5:10 PM, Marco Cassinerio wrote:

Hi,

i'm trying to execute a javascript function on the iPhone and get the return value.

The function is simple:
return "hello";

I'm using a UIWebView and the - stringByEvaluatingJavaScriptFromString: method but, while it works on os x, it doesn't on the iPhone.
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to