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

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

问题描述

有一个问题我想在我的基于浏览器的应用程序做的事情是让用户选择一些文本(不是在< textarea的>中只是简单的醇'的文字!),并有我的应用程序弹出一个小工具栏,然后可以用下一个交互(在我的情况下,添加注释)。

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).

我发现了很多关于谷歌的东西,这似乎是专注于写作WYSIWYG编辑器,但是这不是我想要,然后大部分曾在IE浏览器而不是在FF2或3。理想情况下,我想了一些功能,可以在在 IE7(6如果可能的话)的作品,火狐2和浏览器窗口返回当前选定的文本; 3和Safari 2 。如果它工作在Opera,那将会是一种奖励,但它不是必需的。

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?

推荐答案

看一看 jQuery的和的wrapSelection插件。这可能是你在找什么。

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

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

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