I have several web pages that are used inside a UIWebView that currently link to resources with both a relative and an absolute path:
<link rel="stylesheet" type="text/css" href="/css/path/mycss.css"/> <img src="myimage.png" />
The HTML file itself is located on the path "/page/path/page.html" with myimage.png in the same directory. The same pages are also used for rendering directly in the browser, and ideally I would prefer not to change the paths. On an iPad, the contents of the website are dynamically loaded into the Documents directory for offline viewing. The problem is that there seems to be no way to get UIWebView to handle absolute path resolution. To download the content, I use the following:
NSData *data = [NSData dataWithContentsOfFile:fullPath]; [self loadData:data MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:baseURL];
If I specify baseURL in the "/ page / path" directory, the UIWebView will correctly find myimage.png, but will not find mycss.css. I also tried specifying baseURL in the Documents directory, but this did not resolve the resource. In fact, I could not get UIWebView to fully resolve any absolute paths.
Has anyone been able to get absolute paths to work with UIWebView?
source share