I have a UIWebView in which some parts of it have an <a href="" > <img src="" </a>
in it. I have added a UITapGesture to this UIWebView and so what I want is basically when a user taps on an image, it doesn t bring you to the link pointed to it but rather do something. I am having issues in preventing the image to go to the hyperlink it s pointed to. Any idea? I ve tried injecting javascript so that it changes the href to some fake link when the user taps the image and then on the:
- (BOOL)webView:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
如果与我所看到的怀疑相匹配,我就检查了请求书。 然而,由于以下原因,这并不奏效:
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]);
}
是否有任何其他想法?