javascript Programming Glossary: textrange
How can I position an element next to user text selection? http://stackoverflow.com/questions/1589721/how-can-i-position-an-element-next-to-user-text-selection document.selection.createRange Clone the TextRange and collapse range document.selection.createRange .duplicate..
Character offset in an Internet Explorer TextRange http://stackoverflow.com/questions/164147/character-offset-in-an-internet-explorer-textrange offset in an Internet Explorer TextRange As far as I can tell there's no simple way of retrieving a.. no simple way of retrieving a character offset from a TextRange object in Internet Explorer. The W3C Range object has a node.. the character offset of the start of an Internet Explorer TextRange javascript html internet explorer selection dhtml share improve..
How to find cursor position in a contenteditable DIV? http://stackoverflow.com/questions/2213376/how-to-find-cursor-position-in-a-contenteditable-div using my own Rangy library which adds a wrapper to IE TextRange object that behaves like a DOM Range. A DOM Range consists of..
Is there an Internet Explorer approved substitute for selectionStart and selectionEnd? http://stackoverflow.com/questions/235411/is-there-an-internet-explorer-approved-substitute-for-selectionstart-and-selecti normalizedValue el.value.replace r n g n Create a working TextRange that lives only in the input textInputRange el.createTextRange.. that lives only in the input textInputRange el.createTextRange textInputRange.moveToBookmark range.getBookmark Check if the.. return what we want in those cases endRange el.createTextRange endRange.collapse false if textInputRange.compareEndPoints..
How can I highlight the text of the DOM Range object? http://stackoverflow.com/questions/2582831/how-can-i-highlight-the-text-of-the-dom-range-object this question I would suggest using document 's or the TextRange 's execCommand method which is built for just such a purpose..
How to get the start and end points of selection in text area? http://stackoverflow.com/questions/3053542/how-to-get-the-start-and-end-points-of-selection-in-text-area normalizedValue el.value.replace r n g n Create a working TextRange that lives only in the input textInputRange el.createTextRange.. that lives only in the input textInputRange el.createTextRange textInputRange.moveToBookmark range.getBookmark Check if the.. return what we want in those cases endRange el.createTextRange endRange.collapse false if textInputRange.compareEndPoints..
Creating a collapsed range from a pixel position in FF/Webkit http://stackoverflow.com/questions/3189812/creating-a-collapsed-range-from-a-pixel-position-in-ff-webkit identified by this position. This can be done with the TextRange object in Internet Exporer moveToPoint x y method . How can..
update textarea value, but keep cursor position http://stackoverflow.com/questions/3286595/update-textarea-value-but-keep-cursor-position normalizedValue el.value.replace r n g n Create a working TextRange that lives only in the input textInputRange el.createTextRange.. that lives only in the input textInputRange el.createTextRange textInputRange.moveToBookmark range.getBookmark Check if the.. return what we want in those cases endRange el.createTextRange endRange.collapse false if textInputRange.compareEndPoints..
Inserting text at cursor in a textarea, with Javascript http://stackoverflow.com/questions/3308292/inserting-text-at-cursor-in-a-textarea-with-javascript share improve this question No there isn't. IE has its TextRange objects to do the job. IE 9 and everything else for the last..
IE's document.selection.createRange doesn't include leading or trailing blank lines http://stackoverflow.com/questions/3622818/ies-document-selection-createrange-doesnt-include-leading-or-trailing-blank-li Which works 99 of the time. The problem is that TextRange.text doesn't return leading or trailing new line characters... I didn't like about it which were first that it relies on TextRanges that stray outside the textarea thus harming performance and.. normalizedValue el.value.replace r n g n Create a working TextRange that lives only in the input textInputRange el.createTextRange..
Javascript: Move caret to last character http://stackoverflow.com/questions/4715762/javascript-move-caret-to-last-character textarea As I know this is somehow possible with the TextRange object but I don't really know how to use it EDIT I would love.. el.selectionEnd el.value.length else if typeof el.createTextRange undefined el.focus var range el.createTextRange range.collapse.. el.createTextRange undefined el.focus var range el.createTextRange range.collapse false range.select However you really shouldn't..
Inserting text into an editable IFRAME at the caret position (IE) http://stackoverflow.com/questions/5337752/inserting-text-into-an-editable-iframe-at-the-caret-position-ie which is what I have. In the script I use I am creating a TextRange object from the document of the IFRAME which I use to paste.. try fixing this in IE by saving restoring the selected TextRange as the iframe loses receives focus. Something like this should..
getSelection() not working in IE http://stackoverflow.com/questions/5421892/getselection-not-working-in-ie selection object has a method createRange that returns a TextRange object see this msdn page for details . Note that both the selection..
Full text search in HTML ignoring tags / & http://stackoverflow.com/questions/5886858/full-text-search-in-html-ignoring-tags question You can use window.find in non IE browsers and TextRange 's findText method in IE. Here's an example http jsfiddle.net.. Unfortunately Opera doesn't support either window.find or TextRange . A rather heavyweight alternative is to use a combination of.. heavyweight alternative is to use a combination of the TextRange and CSS class applier modules of my Rangy library as in the..
Highlight text range using JavaScript http://stackoverflow.com/questions/6240139/highlight-text-range-using-javascript without removing the tag. I have tried already using a TextRange object but without success. Thanks in advance javascript selection.. range else if document.selection document.body.createTextRange var textRange document.body.createTextRange textRange.moveToElementText.. var textRange document.body.createTextRange textRange.moveToElementText el textRange.collapse true textRange.moveEnd..
Javascript Text Selection Page Coordinates http://stackoverflow.com/questions/6846230/javascript-text-selection-page-coordinates can use the boundingLeft and boundingTop properties of the TextRange that can be extracted from the selection. Here's a function..
Persisting the changes of range objects after selection in HTML http://stackoverflow.com/questions/13949059/persisting-the-changes-of-range-objects-after-selection-in-html restoreSelection function containerEl savedSel var textRange document.body.createTextRange textRange.moveToElementText containerEl.. savedSel var textRange document.body.createTextRange textRange.moveToElementText containerEl textRange.collapse true textRange.moveEnd.. textRange.moveToElementText containerEl textRange.collapse true textRange.moveEnd character savedSel.end textRange.moveStart..
Javascript Contenteditable - set Cursor / Caret to index http://stackoverflow.com/questions/16095155/javascript-contenteditable-set-cursor-caret-to-index function containerEl start end var textRange document.body.createTextRange textRange.moveToElementText containerEl.. start end var textRange document.body.createTextRange textRange.moveToElementText containerEl textRange.collapse true textRange.moveEnd.. textRange.moveToElementText containerEl textRange.collapse true textRange.moveEnd character end textRange.moveStart..
Set cursor at a length of 14 onfocus of a textbox http://stackoverflow.com/questions/1865563/set-cursor-at-a-length-of-14-onfocus-of-a-textbox node if node return false else if node.createTextRange var textRange node.createTextRange textRange.collapse true textRange.moveEnd.. if node.createTextRange var textRange node.createTextRange textRange.collapse true textRange.moveEnd pos textRange.moveStart pos.. var textRange node.createTextRange textRange.collapse true textRange.moveEnd pos textRange.moveStart pos textRange.select return..
contenteditable, set caret at the end of the text (cross-browser) http://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser else if typeof document.body.createTextRange undefined var textRange document.body.createTextRange textRange.moveToElementText el.. undefined var textRange document.body.createTextRange textRange.moveToElementText el textRange.collapse false textRange.select.. textRange.moveToElementText el textRange.collapse false textRange.select placeCaretAtEnd document.getElementById..
jquery: select text event http://stackoverflow.com/questions/4367353/jquery-select-text-event function var sel document.selection if sel.type Text var textRange sel.createRange if textRange.text selectCallback textRange.parentElement.. if sel.type Text var textRange sel.createRange if textRange.text selectCallback textRange.parentElement document.onmouseup.. sel.createRange if textRange.text selectCallback textRange.parentElement document.onmouseup mouseOrKeyUpHandler document.onkeyup..
JQuery/Javascript - Search DOM for text and insert HTML http://stackoverflow.com/questions/4489119/jquery-javascript-search-dom-for-text-and-insert-html are native methods for finding text inside a document MSIE textRange.findText Others window.find Manipulate the given textRange if.. textRange.findText Others window.find Manipulate the given textRange if something was found. Those methods should provide much more..
Get a range's start and end offset's relative to its parent container http://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container .length else if sel doc.selection sel.type Control var textRange sel.createRange var preCaretTextRange doc.body.createTextRange.. element preCaretTextRange.setEndPoint EndToEnd textRange caretOffset preCaretTextRange.text.length return caretOffset..
Set caret position right after the inserted element in a contentEditable div http://stackoverflow.com/questions/4834793/set-caret-position-right-after-the-inserted-element-in-a-contenteditable-div Math.random .slice 2 html ' span id ' id ' span ' var textRange document.selection.createRange textRange.collapse false textRange.pasteHTML.. ' id ' span ' var textRange document.selection.createRange textRange.collapse false textRange.pasteHTML html var markerSpan document.getElementById.. document.selection.createRange textRange.collapse false textRange.pasteHTML html var markerSpan document.getElementById id textRange.moveToElementText..
how to get selection inside a div using jquery/javascript http://stackoverflow.com/questions/5801347/how-to-get-selection-inside-a-div-using-jquery-javascript Text var selTextRange document.selection.createRange var textRange selTextRange.duplicate textRange.moveToElementText el if selTextRange.compareEndPoints.. var textRange selTextRange.duplicate textRange.moveToElementText el if selTextRange.compareEndPoints EndToStart.. el if selTextRange.compareEndPoints EndToStart textRange 1 selTextRange.compareEndPoints StartToEnd textRange 1 if selTextRange.compareEndPoints..
Full text search in HTML ignoring tags / & http://stackoverflow.com/questions/5886858/full-text-search-in-html-ignoring-tags off else if document.body.createTextRange var textRange document.body.createTextRange while textRange.findText text.. var textRange document.body.createTextRange while textRange.findText text textRange.execCommand BackColor false yellow.. while textRange.findText text textRange.execCommand BackColor false yellow textRange.collapse false..
Highlight text range using JavaScript http://stackoverflow.com/questions/6240139/highlight-text-range-using-javascript if document.selection document.body.createTextRange var textRange document.body.createTextRange textRange.moveToElementText el.. var textRange document.body.createTextRange textRange.moveToElementText el textRange.collapse true textRange.moveEnd.. textRange.moveToElementText el textRange.collapse true textRange.moveEnd character end textRange.moveStart..
How do I shift the visible text in a narrow input element to see the cursor at the end? http://stackoverflow.com/questions/668720/how-do-i-shift-the-visible-text-in-a-narrow-input-element-to-see-the-cursor-at-t scroll to the end of the text. In IE it is easy I create a textRange object put its start and end position at the end of the text..
Select whole word with getSelection http://stackoverflow.com/questions/7380190/select-whole-word-with-getselection word else if sel document.selection sel.type Control var textRange sel.createRange if textRange.text textRange.expand word Move.. sel.type Control var textRange sel.createRange if textRange.text textRange.expand word Move the end back to not include.. Control var textRange sel.createRange if textRange.text textRange.expand word Move the end back to not include the word's trailing..
designMode iFrame Get Cursor Position http://stackoverflow.com/questions/8664504/designmode-iframe-get-cursor-position element preCaretRange.setEndPoint EndToEnd textRange caretOffset preCaretTextRange.text.length return caretOffset..
|