在浏览器中获取选定的文本,跨平台 [英] Getting selected text in a browser, cross-platform

查看:20
本文介绍了在浏览器中获取选定的文本,跨平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的基于浏览器的应用程序中做的一件事是允许用户选择一些文本(不在 <textarea> 中,只是普通的文本!),然后让我的应用程序弹出一个小工具栏,然后可以与下一个交互(在我的例子中,添加注释).

我在 google 上发现了很多似乎专注于编写 WYSIWYG 编辑器的东西,但这不是我想要的,而且大部分内容在 IE 中有效,但在 FF2 中无效或 3. 理想情况下,我想要一些可以返回浏览器窗口中当前选定文本的功能,该功能适用​​于 IE7(如果可能,还有 6)、FireFox 2 &3 和 Safari 2.如果它适用于 Opera,那将是一个奖励,但这不是必需的.

有人有这样的功能吗?或者想知道从哪里开始?

解决方案

看看 jQuerywrapSelection 插件.这可能正是您要找的.

One of the things I'd like to do in my browser-based application is allow the user to select some text (not in a <textarea>, just plain ol' text!), and have my application pop up a small toolbar that then can interact with the next (in my case, add annotations).

I've found a lot of stuff on google that seems to be focused on writing WYSIWYG editors, but that isn't what I want, and most of it worked in IE but not in FF2 or 3. Ideally, I'd like some function that can return the currently selected text in the browser window that works in IE7 (and 6 if possible), FireFox 2 & 3 and Safari 2. If it works in Opera, that'd be a bonus, but it's not a requirement.

Anyone have a function that does this? Or an idea of where to start?

解决方案

Have a look at jQuery and the wrapSelection plugin. It may be what you are looking for.

这篇关于在浏览器中获取选定的文本,跨平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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