UIWebView loadHTMLString not working in iOS5

后端 未结 2 1224
心在旅途
心在旅途 2021-02-05 15:10

Perhaps this is similar to this question, which has no responses: loadHTMLString Not Working With iOS5?

I have a UIWebView which I populate using loadHTMLString:baseURL

相关标签:
2条回答
  • 2021-02-05 15:50

    I'm not an HTML standards expert, but...did you try to close the <script> tag:

    
    <script type="text/javascript" src="./myscript.js"></script>
    
    

    It worked for me.

    0 讨论(0)
  • 2021-02-05 15:51

    The way to load an HTML file that contains embedded folder references, such as '/file.js', is to load it as a URL rather than as a STRING.

    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"htm"];
    NSURL *url = [NSURL fileURLWithPath:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];
    

    I use this along with referenced folders (not referenced files) to create an ordinary website structure in Xcode, with js/ and css/ and images/ references in the embedded index.htm file, e.g.

    <script type="text/javascript" src="js/jquery-1.6.4.min.js"></script>
    

    UPDATE

    I don't think that referencing a URI within a loaded HTML string was officially supported. If you must use a string, then load the needed resource files into the string before you load it into the UIWebView.

    0 讨论(0)
提交回复
热议问题