Injecting Javascript in UIWebView

Written by on April 18, 2011 in Dev Blog - 1 Comment

This is an interesting technique similar to what I’ve talked about in a previous post about extracting data from an UIWebView using the stringByEvaluatingJavaScriptFromString function. Instead of just fetching a value using this method you can inject a complete javascript into the page and call the functions in that javascript to extract data from the html.

I recently wrote an App that used this technique to add a few javascripts into the UIWebView and then called the functions in the script using the stringByEvaluatingJavaScriptFromString call to fetch data transformed into JSON format by the scripts. The javascript functions easily found particular elements in the html and composed a JSON string from them which was returned.

Really neat. Makes it easy to fetch data from websites for your Iphone apps without having to “parse” html code or similar. Instead use the existing javascript language to get what you need in a few simple steps.

About the author

One Reply to Injecting Javascript in UIWebView

  1. Shahriar

    June 2, 2011 • 9:20 am

    Can u please share the source code or the way u did it?

Leave a Reply

Latest apps | Projects

  • Ljushults HBF
  • My Advent Calendar
  • My Gourmet Recipes
  • iCORNR
  • Hammerfall App