2013-10-07 49 views
0

我的Objective-C代碼看起來是這樣的:依奧斯的WebView調用javascript函數不會工作

NSString *test = [NSString stringWithFormat: @"testFunction(%@)", details.name]; 

NSString *userName = [webView stringByEvaluatingJavaScriptFromString:test]; 
NSLog(@"Web response: %@",test); 

此打印出testFunction(the string of details.name here)

我的JavaScript看起來像這樣:

<script type="text/javascript">document.write(title);</script> 

var title; 

function testFunction(var) { 
    title = var; 
} 

回答

0

在JS你在第一線關閉腳本標記留出功能

您的JS應該是這樣的

<script type="text/javascript">document.write(title); 

var title; 

function testFunction(var) { 
    title = var; 
} 
</script>