iPhone开发:在UIWebView上抓取选定/突出显示的文本 [英] iPhone Development: Grabbing selected/highlighted text on UIWebView

查看:91
本文介绍了iPhone开发:在UIWebView上抓取选定/突出显示的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

请告知我如何才能在 UIWebVIew 上获取所选文字。

Please kindly advice on how possibly I can get the selected text on UIWebVIew.

我继续搜索如何处理选定/突出显示的文本并找到以下内容:

I went on to search on how to deal with selected/highlighted text and found the following:

选择和菜单管理


要在视图中复制或剪切某些内容,
必须选择某事。
可以是一系列文本,图像,
URL,颜色或任何其他
表示的数据,包括
自定义对象。要在自定义
视图中实现
复制粘贴行为,您必须自己管理该视图中
对象的选择。如果
用户通过
选择视图中的对象进行特定的触摸手势(对于
示例,双击),您必须处理
该事件,内部 记录
选择
(并取消选择之前的所有
选项),或者在视觉上
表示
视图中的新选择。如果用户可以在
中选择多个对象进行复制剪切粘贴操作,那么
必须实现多选
行为。

To copy or cut something in a view, that "something" must be selected. It can be a range of text, an image, a URL, a color, or any other representation of data, including custom objects. To implement copy-and-paste behavior in your custom view, you must manage the selection of objects in that view yourself. If the user selects an object in the view by making a certain touch gesture (for example, a double-tap) you must handle that event, internally record the selection (and deselect any previous selection), and perhaps visually indicate the new selection in the view. If it is possible for users to select multiple objects in your view for copy-cut-paste operations, you must implement that multiple-selection behavior.

这就是我迷路的地方。 ...记录选择 - 我甚至不确定如何表示选择,更不用说录制它了。

And that's where I got lost. "...record the selection" - I'm not even sure how to represent a selection let alone recording it.

非常感谢任何帮助。 ^^干杯!

Any help is very much appreciated. ^^ Cheers!

亲切的问候,
oonoo

Kind regards, oonoo

推荐答案

您可以使用 stringByEvaulatingJavaScriptFromString 获取UIWebView中当前选定的文本。

You can use stringByEvaulatingJavaScriptFromString to get the currently selected text in a UIWebView.

NSString *selection = [self.webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected Text" message:selection delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
[alert release], alert = nil;

这篇关于iPhone开发:在UIWebView上抓取选定/突出显示的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆