【发布时间】:2012-01-15 18:40:22
【问题描述】:
我有一个 UIWebView,其中的某些部分有一个 <a href="" > <img src="" </a>。我已经向这个 UIWebView 添加了一个 UITapGesture ,所以我想要的基本上是当用户点击图像时,它不会把你带到指向它的链接,而是做一些事情。我在阻止图像转到它所指向的超链接时遇到问题。任何的想法?我尝试注入 javascript,以便在用户点击图像然后点击以下位置时将 href 更改为一些假链接:
- (BOOL)webView:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
我检查了请求 url,如果它与我的假人匹配。但是,这不起作用,由于某种原因,使用以下方法更改了 href 链接:
NSString *stripLink = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).parentNode.href=%@", pt.x, pt.y, @"http://www.fakeurl.com"];
if ([self stringByEvaluatingJavaScriptFromString:stripLink] != nil){
NSString *testHref = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).parentNode.href", pt.x, pt.y];
NSLog(@"FINAL HREF IS %@", [self stringByEvaluatingJavaScriptFromString:testHref]);
}
还有其他想法吗?
【问题讨论】:
标签: iphone objective-c ios ipad uiwebview