ローカルに保存された Web ページ (HTML+CSS+JS) を表示するアプリケーションを構築しています。さまざまな方法を試しましたが、ページが Java スクリプトに応答しません。これが私が試したコードの一部です
トライ: 1
//html
NSString *actualPageMarkupFilePath = [[NSBundle mainBundle] pathForResource:@"inex" ofType:@"html"];
NSData *actualPageMarkupData = [NSData dataWithContentsOfFile:actualPageMarkupFilePath];
NSString *actualPageMarkup = [[NSString alloc]initWithData:actualPageMarkupData encoding:NSASCIIStringEncoding];
// load css styles
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"style" ofType:@"css"];
NSData *cssData = [NSData dataWithContentsOfFile:cssPath];
NSString *cssString = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding];
// load js
NSString *jsPath1 = [[NSBundle mainBundle] pathForResource:@"myzepto" ofType:@"js"];
NSData *jsData1 = [NSData dataWithContentsOfFile:jsPath1];
NSString *jsString1 = [[NSString alloc] initWithData:jsData1 encoding:NSASCIIStringEncoding];
NSString *jsPath2 = [[NSBundle mainBundle] pathForResource:@"zepto.min" ofType:@"js"];
NSData *jsData2 = [NSData dataWithContentsOfFile:jsPath2];
NSString *jsString2 = [[NSString alloc] initWithData:jsData2 encoding:NSASCIIStringEncoding];
// compose full html page
NSString *pageContent = [NSString stringWithFormat:@"%@%@%@%@", cssString, jsString1, jsString2, actualPageMarkup];
[self.HTMLWebView loadHTMLString:pageContent baseURL:[NSURL URLWithString:@""]];
トライ: 2
NSString *filePath =
[[NSBundle mainBundle] pathForResource:@"inex" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
if (htmlData) {
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle bundlePath];
NSString *fullPath = [NSBundle pathForResource:@"inex"
ofType:@"html" inDirectory:path];
[_HTMLWebView loadRequest:[NSURLRequest requestWithURL:
[NSURL fileURLWithPath:fullPath]]];
}
トライ: 3
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"inex" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
[_HTMLWebView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] resourcePath]]];
トライ: 4
NSURL *urlPageFile = [[NSBundle mainBundle] URLForResource:@"inex" withExtension:@"html"];
NSURLRequest *webPageRequest = [[NSURLRequest alloc] initWithURL:urlPageFile];
[_HTMLWebView loadRequest:webPageRequest];
[webPageRequest release];