如何以编程方式在UIWebView中输入“选择模式”?

时间:2022-08-24 23:57:04

I'm trying to create an iBooks like experience, where users can highlight text within a document. To do that, I'm using a UIWebView with my document in an HTML format.

我正在尝试创建类似iBooks的体验,用户可以在文档中突出显示文本。为此,我使用UIWebView和HTML格式的文档。

I've figured out how to capture the initial selection highlight, but can't make it so the user can edit or change their highlight once made.

我已经弄清楚如何捕捉初始选择高亮,但无法做到这一点,以便用户可以编辑或更改他们的高亮一旦制作。

I'm hoping to pre-define a javascript Selection DOM Object with the Range of the highlight and then programmatically enter 'selection mode'. It seems that you can only enter selection mode by long-pressing on a piece of text, and then automatically creates the Selection DOM Object for you.

我希望预先定义一个带有高亮范围的javascript选择DOM对象,然后以编程方式输入'选择模式'。您似乎只能通过长按一段文本进入选择模式,然后自动为您创建Selection DOM对象。

How do you programmatically enter selection mode with a UIWebView?

如何以编程方式使用UIWebView进入选择模式?

2 个解决方案

#1


1  

Does the following SO question help?

以下SO问题是否有帮助?

Highlight text range using JavaScript

使用JavaScript突出显示文本范围

Or look at

或者看看

https://code.google.com/p/rangy/

Rangy is a cross-browser JavaScript range and selection library.

Rangy是一个跨浏览器的JavaScript范围和选择库。

#2


1  

You can manipulate the web page by directly executing Javascript strings in it. There is a method:

您可以通过直接在其中执行Javascript字符串来操作网页。有一种方法:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)javascriptString

in UIWebView. This will execute arbitrary script in your page's DOM. Use this with some jQuery maybe you will be able to do that. So maybe you need to interact with your DOM heavily to emulate this.

在UIWebView中。这将在页面的DOM中执行任意脚本。使用这个与一些jQuery也许你将能够做到这一点。因此,您可能需要与DOM进行大量交互才能模拟这一点。

#1


1  

Does the following SO question help?

以下SO问题是否有帮助?

Highlight text range using JavaScript

使用JavaScript突出显示文本范围

Or look at

或者看看

https://code.google.com/p/rangy/

Rangy is a cross-browser JavaScript range and selection library.

Rangy是一个跨浏览器的JavaScript范围和选择库。

#2


1  

You can manipulate the web page by directly executing Javascript strings in it. There is a method:

您可以通过直接在其中执行Javascript字符串来操作网页。有一种方法:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)javascriptString

in UIWebView. This will execute arbitrary script in your page's DOM. Use this with some jQuery maybe you will be able to do that. So maybe you need to interact with your DOM heavily to emulate this.

在UIWebView中。这将在页面的DOM中执行任意脚本。使用这个与一些jQuery也许你将能够做到这一点。因此,您可能需要与DOM进行大量交互才能模拟这一点。