Skip to content

Instantly share code, notes, and snippets.

@yeahq
Created April 17, 2012 00:55
Show Gist options
  • Save yeahq/2402648 to your computer and use it in GitHub Desktop.
Save yeahq/2402648 to your computer and use it in GitHub Desktop.
Run Javascript in UIWebView
// From: http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview
NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function myFunction() { "
"var field = document.getElementById('field_3');"
"field.value='Calling function - OK';"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
[webView stringByEvaluatingJavaScriptFromString:@"myFunction();"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment