• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: -stringByEvaluatingJavaScriptFromString: return value iphone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -stringByEvaluatingJavaScriptFromString: return value iphone


  • Subject: Re: -stringByEvaluatingJavaScriptFromString: return value iphone
  • From: Peter Blazejewicz <email@hidden>
  • Date: Sat, 31 Jan 2009 22:10:06 +0100

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@hidden)

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:
This email sent to email@hidden


References: 
 >-stringByEvaluatingJavaScriptFromString: return value iphone (From: Marco Cassinerio <email@hidden>)

  • Prev by Date: New NSZombie warning on CFRunLoopTimer
  • Next by Date: Flowing text between text fields
  • Previous by thread: -stringByEvaluatingJavaScriptFromString: return value iphone
  • Next by thread: Re: -stringByEvaluatingJavaScriptFromString: return value iphone
  • Index(es):
    • Date
    • Thread