I have a well formed html file, let’s call it index.html. It is in the app bundle. This file contains links to css style sheets and local javascript files. If I use
[self.ourWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
all of the javascript/css items in the file work just fine.
If however I read the contents of the file into a string(and update the string to escape the ” and / items) then use
[ourWebView loadHTMLString:HTMLString baseURL:nil];
The html markup gets rendered, but none of the javascript/css gets honored or executed.
I even tried reading from the known good file, rewriting to another file in the Documents directory, and then using loadRequest to load it. That does not execute the javascript either.
Am I missing something obvious?
Thanks,
Ken
(Mashup of my comments above)
You claim that:
using the following code:
You need to pass the appropriate value to the
baseURLparameter instead ofnil. This value depends on where your javascript/css files are within the bundle.Later, in the comments, you say that:
And you have modified the code to the following (taken from your comments):
The way you are creating the path does not seem right.
NSStringhas a number of methods to work with paths. Use them.Replace:
with this: