点击链接时有关UIWebview的问题 [英] Question about UIWebview when tapping links
本文介绍了点击链接时有关UIWebview的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UIWebView,它加载一个html文件。用户单击链接后,我希望在自定义UIWebview中打开该URL。
我尝试了一些操作:
I have an UIWebView which loads an html-file. Once the user clicks a link, i want the url to open in a custom UIWebview. I tried some things:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyiPadHTML"
ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
else {
NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyHTML"
ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:htmlPath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
这是我,正在加载文件,具体取决于设备。很好。我是在-(void)viewDidLoad
method
This is me, loading the files, depending on the device. That works great. I did it in the - (void)viewDidLoad
method
推荐答案
应该
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if ( navigationType == UIWebViewNavigationTypeLinkClicked ) {
[myOtherCustomWebView loadRequest:request];
return NO;
}
return YES;
}
这篇关于点击链接时有关UIWebview的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文