tags:

views:

129

answers:

1

When i call stringByEvaluatingJavaScriptFromString to call a javascript method, iphone is "suspended" (can not do any thing on iphone)

NSString *_script = [[NSString alloc] initWithString: @"onTest()"];
[[NSString alloc] initWithString: [webView stringByEvaluatingJavaScriptFromString: _script]];

onTest() method is defined in local resource index.html.

Please tell me what is the reason?

A: 

stringByEvaluatingJavaScriptFromString has a in-built "kill timer" (which is my way of calling it) of 5 sec. If your javascript is complex, and runs for more than 5 sec, the iPhone OS kills the thread making your iPhone look suspended.

May be you can wait for iPhone OS 3.0 which promises faster Javascript processing (and may be who knows they could increase the kill timer seconds)

Mugunth Kumar
my js method is very simple. It is defined like below: function onTest(){ alert("hello"); return "ok";}And iphone still is suspended.
That does nothing visible... shouldn't you have a (function onTest(){})() to actually call your code?
Robert Gould