【问题标题】:loading links in in-app browser in a web view in iphone在 iphone 的 web 视图中加载应用内浏览器中的链接
【发布时间】:2011-09-24 09:06:07
【问题描述】:

我在资源中有一些本地 html 文件。在启动一个 html 时,比如 a.html,在 webview 中加载。该 webview 中有一些超链接(或者说 html 内容),它们是我资源中其他 html 文件的链接。现在单击这些链接我想在应用内浏览器中打开它们。

如何做到这一点。 有什么想法????

谢谢!!!!

【问题讨论】:

    标签: iphone html ios4 uiwebview


    【解决方案1】:

    我没有尝试过,但它可能会起作用!

    创建你的 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多