views:

245

answers:

1

Hi!

I am loading a page into a WebView. The page has this little-test Javascript:

<script type="text/javascript">
function test(parametr)
{

  $('#testspan').html(parametr);

}

var bdu = (function(){
 return {
  secondtest: function(parametr) {

  $('#testspan').html(parametr);

  }
 }
})();
</script>

The problem is that I can't call the "secondtest" function from cocoa

this is perfectly work:

[[webview1 windowScriptObject] callWebScriptMethod:@"test" withArguments:arguments];

and this is not working:

[[webview1 windowScriptObject] callWebScriptMethod:@"bdu.secondtest" withArguments:arguments];

What would cause this problem and how do I fix it?

Thanks

A: 

callWebscriptMethod:(NSString*)name withArguments:(NSArray*)args:

does not evaluate name as a Javascript expression. So it can't parse bdu.secondtest: it doesn't look up bdu first, then get the entry secondtest in it.

Instead, just use evaluateWebScript:.

Yuji