2

I am using WebView to load locally referenced HTML files into my app. I have the folder structure:

-assets/
   -www/
     -css/
     -images/
     -js/
     -index.html

index.html uses relative paths to link to the various css, javascript and image files eg:

<script src="js/functions.js" type="text/javascript"></script>
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" >

Because I am using relative paths I am loading the HTML content into the WebView by using this code in ViewController.h

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"assets/www"]];
[webView loadRequest:[NSURLRequest requestWithURL:url]];

When I run the iOS simulator the page successfully loads and displays an image from the images folder on the page. However the CSS and Javascript files do not load. Where am I going wrong?

3
  • try running the same in safari and check error in console. Commented Mar 5, 2014 at 10:50
  • The page launches correctly in Safari with no errors Commented Mar 5, 2014 at 11:11
  • 1
    I cleaned up the Build. Product -> Clean and the page loaded with the CSS and Javascript. Commented Mar 5, 2014 at 12:01

1 Answer 1

1

Change path to file .js and .css like this:

 <script src="../js/functions.js" type="text/javascript"></script>
 <link href="../css/style.css" media="screen" rel="stylesheet" type="text/css" >
Sign up to request clarification or add additional context in comments.

1 Comment

The files aren't down a directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.