title: UIWebView and local css file
body: <p>I want to style a web page meant for the desktop so that it is presentable on a UIWebView on iPhone. I do not have access to the web server from which the pages originate. I would like to do this by changing the <code>href</code> attribute of the <code>&lt;link&gt;</code> stylesheet element programmatically.</p>
  
  <p>I do the following with my <code>IBOutlet UIWebView *webView</code>.</p>
  
  <pre><code>NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"MyStyleSheet" 
                                                      ofType:@"css"];
  NSString *js = @"document.getElementsByTagName('link').setAttribute('href','";
  NSString *js2 = [js stringByAppendingString:cssPath];
  NSString *finalJS = [js2 stringByAppendingString:@"');"];
  
  //check element structure
  NSString *res = [webView stringByEvaluatingJavaScriptFromString:finalJS]; 
  </code></pre>
  
  <p>This does not work. Using the <code>[webView stringByEvaluatingJavaScriptFromString:]</code> message and making a change to the <code>backgroundColor</code> of the body does indeed work - done as an exercise to see if I was using the call correctly.</p>
  
  <p>Am I barking up the wrong tree?</p>