我需要从UIWebView中选择一些文本。我提到了这个答案Getting selected elements programatically from uiwebview?但是当我使用点按它选择文字时。但它也显示了所有HTML字符Selected Name: 1 Name of instrument
-(void)singleTap:(UIGestureRecognizer *)gestureRecognizer
{
NSLog(@"single tap");
CGPoint touchPoint = [gestureRecognizer locationInView:wbCont];
//NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).toString()", touchPoint.x, touchPoint.y];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", touchPoint.x, touchPoint.y];
NSString * tagName = [wbCont stringByEvaluatingJavaScriptFromString:js];
NSLog(@"Selected Name: %@",tagName);
}
答案 0 :(得分:0)
我从stringByReplacingOccurrencesOfString:
函数得到答案。我用下面的代码。它工作正常。
tagName=[tagName stringByReplacingOccurrencesOfString:@" " withString:@""];