title: Loading javascript into a UIWebView from resources
body: <p>I need to load javascript files from my apps resources folder. As of right now, it does read images from the resources just fine, but it's not reading javascripts for some reason. </p>
  
  <p>I have been able to render html docs that reference these javascripts if the html files themselves are written into the resources, but I would like to render html/js by setting the html of a UIWebView so it can be dynamic.</p>
  
  <p>Here is what I am doing:</p>
  
  <pre><code>NSString * html = @"&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;MathJax&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;script type=\"text/x-mathjax-config\"&gt;MathJax.Hub.Config({tex2jax: {inlineMath: [[\"$\",\"$\"],[\"\\(\",\"\\)\"]]}});&lt;/script&gt;&lt;script type=\"text/javascript\" src=\"/MathJax/MathJax.js\"&gt;&lt;/script&gt;$$\\int_x^y f(x) dx$$&lt;img src=\"coffee.png\"&gt;&lt;/body&gt;&lt;/html&gt;";
  
  NSString * path = [[NSBundle mainBundle] resourcePath]; 
  path = [path stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
  path = [path stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
  
  NSString * resourcesPath = [[NSString alloc] initWithFormat:@"file://%@/", path];
  [webview loadHTMLString:html baseURL:[NSURL URLWithString:resourcesPath]];
  </code></pre>
  
  <p>Now, if I change the base url to my server which also has the required files, it does load correctly. It would be great to not require an internet connection. Any help is appreciated!!!  ;)</p>
  
  <p>I found this useful in getting images to display: <a href="https://stackoverflow.com/questions/1926117/iphone-dev-uiwebview-baseurl-to-resources-in-documents-folder-not-app-bundle">iPhone Dev: UIWebView baseUrl to resources in Documents folder not App bundle</a></p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Instead of doing the string replacing and URL encoding, I was able to get images to by simply calling resourceURL on the mainBundle, but still no javascript execution.</p>
  
  <pre><code>    NSString * setHtml = @"&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;MathJax&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;script type=\"text/x-mathjax-config\"&gt;MathJax.Hub.Config({tex2jax: {inlineMath: [[\"$\",\"$\"],[\"\\(\",\"\\)\"]]}});&lt;/script&gt;&lt;script type=\"text/javascript\" src=\"/MathJax/MathJax.js\"&gt;&lt;/script&gt;$$\\int_x^y f(x) dx$$&lt;img src=\"images/test.png\"&gt;&lt;/body&gt;&lt;/html&gt;";
      [webview loadHTMLString:setHtml baseURL:[[NSBundle mainBundle] resourceURL]];
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>If you want to help give this a shot, I have made it easier for you by creating an example project!</p>
  
  <p><a href="https://github.com/pyramation/math-test" rel="noreferrer">https://github.com/pyramation/math-test</a></p>
  
  <pre><code>git clone git@github.com:pyramation/math-test.git
  </code></pre>