Is it possible to send a hash tag to a file url in UIWebView?

I've not tried this but how about loading the file normally without the hashtag and implementing the UIWebViewDelegate with something like this?

- (void)webViewDidFinishLoad:(UIWebView *)webView {
   [webView stringByEvaluatingJavaScriptFromString:@"window.location.href = '#hashtag';"];
}

References:

  • UIView that takes you to anchor link
  • Programmatically scroll to an Anchor Tag

This is how I do it in my code. I append the hashmark to the NSString, then I turn it into an NSURL using fileURLWithPath. Then I replace all instances of %23 back into a #. Its all explained in the code below, but let me know if you have any questions.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"someFile" ofType:@"html"];    
    NSString *filePathWithHash = [NSString stringWithFormat:@"%@#yourDesiredHashTagHere",filePath];
    NSURL *theURL = [NSURL fileURLWithPath:filePathWithHash];
    //NSURL turns the # into %23 when using fileURLWIthPath. So we need to change it back:
    NSString *finalURLString = [[NSString stringWithFormat:@"%@",theURL] stringByReplacingOccurrencesOfString:@"%23" withString:@"#"];
    //Then we need to change it back to an NSURL
    NSURL *finalURL = [NSURL URLWithString:finalURLString];
    //And finally we load this in the webView
    [theWebView loadRequest:[NSURLRequest requestWithURL:finalURL]];

As to %23 issue, I don't think Scott Kohlert's replace solution is good.

The following solutions seems better, I just copied it from here

NSURL *baseUrl = [NSURL fileURLWithPath:stringUrl];
NSURL *fullURL = [NSURL URLWithString:@"#jumpto" relativeToURL:baseUrl];

A little bit off topic, I found the Safari on iOS 6.0, 6.1 behaves differenly than on iOS 5.1 and other desktop browsers(including Safari for OSX) regarding handle URL with anchor. For one of my particular document, whether in UIWebview or mobile Safari on iOS 6.0 or 6.1, upon the first load, the page isn't scrolled to the right position, a reload will fix it. Maybe it has something to do with the fact that part of the html is produced by javascript dynamically. Any ideas?