Fork me on GitHub

UIWebView加载本地页面

//加载Bundle中的html文件。
NSString *Path = [[NSBundle mainBundle] pathForResource:@"chat.html" ofType:nil];
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:Path]]];

// 执行其中的Javascript
NSString *str = [NSString stringWithFormat:@"addmsg(\"%c%c%c\")", 'A', 'A', 'A'];

NSString *Value = [WebView stringByEvaluatingJavaScriptFromString:str];
NSLog(@"%@", Value);


// 加载字符串html代码,并且显示其中的资源文件。
NSString *html = @"<html><body><img src='a.png'></body></html>";
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *base = [NSURL fileURLWithPath:path];

[WebView loadHTMLString:html baseURL:base];

posted on 2012-03-01 15:50  pengyingh  阅读(231)  评论(0)    收藏  举报

导航