例子:
- (void)viewDidLoad { [super viewDidLoad]; //WebView load //cteate webview //动态创建 _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; [self.view addSubview:_webView]; _webView.delegate = self; SingleHtmlCollection *theSingleHtml = self.singleHtml; NSString *urlAddress = theSingleHtml.urladdress; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:240]; [_webView loadRequest:request]; }
在本地实现加载界面:
NSString *aboutPath = [[NSBundle mainBundle] pathForResource:@"aboutbook" ofType:@"html"]; url = [[NSURL alloc] initFileURLWithPath: aboutPath];
获取当前网页的html的title等信息
例子:
- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; //get html title and url self.singleHtml.urladdress = [_webView stringByEvaluatingJavaScriptFromString:@"document.URL"]; self.singleHtml.titleName = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"]; }
想要获取其他的信息,可参考
http://blog.csdn.net/wangyx810328/article/details/7289217
在点击WebView中的html链接时,是否跳转
例子:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ NSString *strUrl = [request.URL absoluteString]; if ([strUrl isEqualToString:[_dataController objectInListAtIndex:_intActiveIndex].urladdress]) { return YES; }else{ //push new controller WebDetailBySYViewController *detailViewController = [[WebDetailBySYViewController alloc] init]; SingleHtmlCollection * aSingleHtml = [[SingleHtmlCollection alloc] init]; aSingleHtml.urladdress = strUrl; aSingleHtml.titleName = [_dataController objectInListAtIndex:_intActiveIndex].titleName; detailViewController.singleHtml = aSingleHtml; //detailViewController.bookMarkFlag = YES; detailViewController.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:detailViewController animated:YES]; NSLog(@"nav controller = %@", self.navigationController); return NO; } }