How to load NSURL which contains hash fragment “#” with UIWebView?

前端 未结 4 1826
刺人心
刺人心 2021-01-11 20:16

Given a local URL address like index.html

Now I need to use UIWebView to load it in iPad. I followed these steps:

  1. Create NSURL

    <
4条回答
  •  心在旅途
    2021-01-11 20:45

    User URLWithString to append fragment to your url, like this:

    *NSURL *url = [NSURL fileURLWithPath:htmlFilePath];
    url = [NSURL URLWithString:[NSString stringWithFormat:@"#%@", @"yourFragmentHere"] relativeToURL:url];*
    

    Hope it will help :)


    EDIT: Swift 3 version:

    var url = URL(fileURLWithPath: htmlFilePath)
    url = URL(string: "#yourFragmentHere", relativeTo: url)
    

提交回复
热议问题