Skip to content Skip to sidebar Skip to footer

How To Call Html File With Css, Js And Images?

I am downloading zip file from server. In NSCachesDirectory I have the html file and I would like to know how to run html file with their source files, I have pasted my code. pleas

Solution 1:

This is an approach for you. From the context that you said that you have source files js and css.

Here issue may be because of on run time these files are not loaded or compiler not able to find their location.

For exmaple:

<!--For CSS file html tag is--><linkrel="stylesheet"href="styles.css"><!--For JS file html tag is--><scripttype="text/javascript"src="exmample.js"></script>

So you have to manually provide location of these files.

See the tags here href and src. These are location of resource files which will required on runtime when your html page is loaded in memory.

How ever if these files are in same directory than there is no need to provide url

Suggestion:

It is advisable that you provide file location url here. Edit your html file and add markers for the url tags.

Example code:

<html><head><scripttype="text/javascript"src="#JS-FILE1#"></script>
        <linkrel="stylesheet"href="#CSS-FILE1#"></head><body></body></html>

You can see that I have replaced files with markers #JS-FILE1# and #CSS-FILE1#. Now we will replace these markers with actual urls before loading html file.

NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"html"];
NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

// Location of Resource filesNSString *jsFilePath = [[NSBundle mainBundle] pathForResource:@"exmample" ofType:@"js"];

NSString *cssFilePath = [[NSBundle mainBundle] pathForResource:@"stylesheet" ofType:@"css"];

html = [html stringByReplacingOccurrencesOfString:@"#JS-FILE1#" withString:jsFilePath];
html = [html stringByReplacingOccurrencesOfString:@"#CSS-FILE1#" withString:cssFilePath];

Put here break point and debug the output string. NSLog this string copy it and create temporary file - open it in browser to cross check that all resources are loaded or not?

If not then check that url for resource files are correct.

Post a Comment for "How To Call Html File With Css, Js And Images?"