textselection

JavaScript / jQuery: how to get selected text in Firefox

三世轮回 提交于 2019-12-11 08:23:30
问题 how can I get the selected text (in a contenteditable div) in Firefox ? It would be enough for recent versions, no need to cover old versions. Say I have a contenteditable div that looks like the below and someone selects a text there and then hits a button, how can I copy the selected text to the clipboard or a variable ? Example: <div class='editInput' id='editInput'>Some awesome text</div> My current function (working in IE): function GetSelection() { if (typeof window.getSelection !=

How to get selected text from textbox control with javascript

那年仲夏 提交于 2019-12-11 03:33:17
问题 I have a textbox and a link button. When I write some text, then select some of them and then click the link button, selected text from textbox must be show with a messagebox. How can I do it? When I click the submit button for textbox below, message box must show Lorem ipsum. Because "Lorem ipsum" is selected in the area. If I select any text from the page and click the submit button it is working, but if I write a text to textbox and make it, it's not. Because when i click to another space,

Calculating xy-position of text selection

有些话、适合烂在心里 提交于 2019-12-11 01:33:45
问题 I am trying to create my own text selection with DOM-elements. Yes, I mean the blue background you see behind the text when you select it in this element. The idea is to halt the default behavior (the blue color) and use my own elements to do the job by finding the xy-position of the selection and then placing absolute positioned elements. I want to be able to do this with a regular div . I'm thinking I need 3 elements. One for the top row (which may be incomplete), one for the middle chunk,

How can I: Select a paragraph with JavaScript (on click)?

亡梦爱人 提交于 2019-12-10 16:16:23
问题 Is it possible to select all the text an an element (e.g., a paragraph <p> ) with JavaScript? A lot of people think jQuery .select() would do this, but it does not. It merely triggers an event. Note that DOM objects for <input> elements have a native select() method, but most other elements (such as <output> and <p> ) do not. (Do I need to use content-editable to get this to work?) 回答1: If you need to support later browsers, i.e., IE9+, you can use the following http://jsfiddle.net/q04jp0qx/2

Setting caret position in JTextArea

我只是一个虾纸丫 提交于 2019-12-10 13:54:15
问题 I have a JTextArea. I have a function that selects some amount of text when some combination is called. It's done properly. The thing is, I want to move caret to the selection beginning when some text is selected and VK_LEFT is pressed. KeyListener is implemented properly, I tested it in other way. The thing is, that when I write following code: @Override public void keyPressed( KeyEvent e) { if(e.getKeyChar()==KeyEvent.VK_LEFT) if(mainarea.getSelectedText()!=null) mainarea.setCaretPosition

jqueryUI Sortable: handling .disableSelection() on form inputs

半腔热情 提交于 2019-12-09 05:37:47
问题 example: i have an un-ordered list containing a bunch of form inputs. after making the ul .sortable(), I call .disableSelection() on the sortable (ul) to prevent text-selection when dragging an li item. ..all fine but I need to re/enable text-selection on the form inputs.. or the form is basically un-editable .. i found a partial solution @ http://forum.jquery.com/topic/jquery-ui-sortable-disableselection-firefox-issue-with-inputs enableSelection, disableSelection seem still to be un

How can I stop text from being selected?

旧巷老猫 提交于 2019-12-09 05:29:19
问题 In my web app the user can sometimes click the same button a number of times, skipping through messages and things, causing the </a> to be selected. So how can I prevent this using Javascript (jQuery) 回答1: This solution worked for me: http://chris-barr.com/entry/disable_text_selection_with_jquery/ $(function(){ $.extend($.fn.disableTextSelect = function() { return this.each(function(){ if($.browser.mozilla){//Firefox $(this).css('MozUserSelect','none'); }else if($.browser.msie){//IE $(this)

jQuery - get selection's paragraph, length, etc

柔情痞子 提交于 2019-12-08 13:35:17
问题 I'm trying to accomplish something I believe should be simple to do in jQuery. I have a long text in my website. Whenever a user selects (highlights) a text, I need to get the following info: The paragraph where the selection begins at The char in that paragraph that the selection starts at The length of the selection The paragraph where the selection ends at (in case the highlight goes beyond one paragraph) The char in that paragraph where the selection ends Thanks ahead ;) 回答1: I think I've

WinAPI: Getting text selection of active window without using the clipboard

喜夏-厌秋 提交于 2019-12-08 03:28:15
问题 I know that you can get the text selection by sending a WM_COPY message and then reading the new contents of the clipboard. But how does Windows retrieve the text selection in the first place before it gets stored in the clipboard? I mean there has to be a way to get the text without sending it to the clipboard, right? But all I could find online were workarounds that write to the clipboard and then quickly restore the old contents.. That's not what I'm looking for, though. (This question is

Get selected text on IPad 2 with Javascript

寵の児 提交于 2019-12-07 18:52:19
问题 I'am developing a web-application that allows to select parts of an html document and put some kind of annotation on it. To get hold of the selected text I use window.getSelection() which works pretty fine in IE9, FF, and Safari. However I run into trouble when using the same page on my IPad 2: If I just select a word by tapping it for a sec, window.getSelection() returns the proper selection. If I create a text range ( as discribed here http://blog.laptopmag.com/how-to-select-copy-and-paste