WebView loading local HTML CSS JavaScript file path attempt

Source: Internet
Author: User

One: There are three ways to load data UIWebView:

1:-(void) Loadrequest: (Nsurlrequest *) request

    NSString * Path = [[NSBundle mainbundle] Pathforresource:@ "demofolder" ofType:@ " HTML " ];     *url = [Nsurl Urlwithstring:path];    [Self.webview1 loadrequest:[nsurlrequest Requestwithurl:url];

Where the URL can be remote or local.

2:-(void) loadhtmlstring: (NSString *) string BaseURL: (Nsurl *) BaseURL

    NSString * Path = [[NSBundle mainbundle] Pathforresource:@ "demofolder" ofType:@ " HTML " ];    [Self.webview1 loadhtmlstring:htmlstring Baseurl:[nsurl Urlwithstring:path];

3:-(void) LoadData: (NSData *) data MIMEType: (NSString *) MIMEType textencodingname: (NSString *) Textencodingname BaseURL :(nsurl*) BaseURL

Data is a file, MimeType is a file type, Textencodingname is an encoding type, and BaseURL is a material resource path

  NSString * Path = [[NSBundle mainbundle] Pathforresource:@ " demofolder   oftype:@"  html    * htmlstring = [NSString Stringwithcontentsoffile:path encoding:    Nsutf8stringencoding Error:nil];    NSData  * htmldata = [htmlstring datausingencoding:nsutf8stringencoding]; [Self.webview1 loaddata:htmldata MIMEType:  @ " text/html   " textencodingname:@"  utf-8   Baseurl:[nsurl Urlwithstring:path]];  

Two: BaseURL is the path that you set up to load the resources needed for HTML.

Because the front-end specifications are CSS files and JavaScript files, as well as the picture files are grouped into a single door folder, so I created three folders: CSS, JavaScript, pic which are stored city.css, alert.js, test22.png

Then pull these files down the bundle and discover whether the Group folder or the Entity folder, Css,js and pictures are not loaded.

Then remove the folder, leaving only the individual files:

  

This will load up normally. Instead, replace the BaseURL path with the path to the CSS file:

NSString * basestring = [[NSBundle mainbundle] Pathforresource:@ "City" ofType:@ " CSS " ];     * BaseUrl = [Nsurl urlwithstring:basestring];

Files can also be loaded out, JS and pictures display normal.

Do not know if there is no other way to keep the HTML file path, write to the document folder directory? Well, waiting to be tested ...

 

WebView loading Local HTML CSS JavaScript file path attempt

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.