【发布时间】:2011-09-24 09:06:07
【问题描述】:
我在资源中有一些本地 html 文件。在启动一个 html 时,比如 a.html,在 webview 中加载。该 webview 中有一些超链接(或者说 html 内容),它们是我资源中其他 html 文件的链接。现在单击这些链接我想在应用内浏览器中打开它们。
如何做到这一点。 有什么想法????
谢谢!!!!
【问题讨论】:
标签: iphone html ios4 uiwebview
我在资源中有一些本地 html 文件。在启动一个 html 时,比如 a.html,在 webview 中加载。该 webview 中有一些超链接(或者说 html 内容),它们是我资源中其他 html 文件的链接。现在单击这些链接我想在应用内浏览器中打开它们。
如何做到这一点。 有什么想法????
谢谢!!!!
【问题讨论】:
标签: iphone html ios4 uiwebview
我没有尝试过,但它可能会起作用!
创建你的 UIWebView 并从你的包中加载第一个 html 文件
NSString *file = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"html"];
NSString *html = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:[NSString stringWithFormat:@"<html><head></head><body>%@</body></html>", html] baseURL:baseURL];
webView.delegate = self;
然后在用户点击链接时获取
-(BOOL)webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if (inType == UIWebViewNavigationTypeLinkClicked) {
// Find which link is selected, get the file and load it into the UIWebView
}
return YES;
}
【讨论】: