如果我有 x,y 坐标,我可以像这样访问 HTML 元素的内容:
location = [aTouch locationInView:myWebView];
NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).innerHTML", location.x, location.y];
NSString *text = [myWebView stringByEvaluatingJavaScriptFromString:js];
但是,我无法保留以后访问它的参考:
NSString *js2 = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f)", location.x, location.y];
NSString *tagName = [myWebView stringByEvaluatingJavaScriptFromString:js2];
...至少不会,除非元素有名称,而且我无法控制 HTML,所以我不能只添加它。
有什么建议么?