getselection

How to support multiple text selections cross browser?

I am building a web-based annotation tool, where end users can select and annotate a section of text from an HTML document. Programmatically speaking, accessing and working with the selected text and corresponding range is straightforward using "window.getSelection" and "getRangeAt". I am running into a problem, however, when I try to...

getting selected text from another frame

I have a frameset where I would like to have someone be able to click a button in one frame that does something with the text selected in the other frame. The button in frame[0] invokes the following javascript to get the selected text from frame[1]: self.parent.frames[1].getSelection() The problem, I believe, is that the very act of ...

Access Iframe with Javascript on external domain

Hi. I'm looking for a way to access read-only properties of a page on a IFRAME. Specifically I would like to read the selection. Apparently I can't read it because the document lies on another domain. Is there a way to read them? ...

What's the best way to set cursor/caret position?

If I'm inserting content into a textarea that TinyMCE has co-opted, what's the best way to set the position of the cursor/caret? I'm using tinyMCE.execCommand("mceInsertRawHTML", false, content); to insert the content, and I'd like set the cursor position to the end of the content. Both document.selection and myField.selectionStart won...

xul-Get selection html

Hello, I have the following function that is supposed to get HTMLs for the user selected area on the web page. This function does not seems to work properly. Sometime, it gets htmls which is not selected also. Can anyone please look into this function? -- Thanks a lot. //----------------------------Get Selected HTML-----------------...

getSelection() and insertNode -- Javascript Text Selection

Does anyone know how to set the browser selection to a newly / independently created range? I understand how to get the text selection from the browser, and I understand how to create a range, but I don't know how to tell the browser to change the selection to the range I've created. I would have thought it would be something like "setSe...

getSelection() for iPhone bookmarklet

I've done a bit of research but can't seem to find a definitive answer regarding getting the currently selected text via getSelection() in an iPhone bookmarklet. Is this still possible? It seems that from various searches there are a number of bookmarklets available that use a similar behaviour, but none appear to work for me. I'm simpl...

What's the best way to find the first common parent of two DOM nodes in javascript?

My question is exactly that but in context I want to examine the selection object, compare the anchorNode and focusNode and if they are different then find the first common parent element. var selected = window.getSelection(); var anchor = selection.anchorNode; var focus = selection.focusNode; if ( anchor != focus ) { // find common...

getSelection() by Double Click or manual selection is not the same

Hi all, I allow me to ask a question, because I have a little probleme with an function which returns me the parent of a selection. $('input[type=button].btn_transform').click(function(){ var selectionObj = getSelected();//Function which gives me selection var theParent=selectionObj.anchorNode.parentNode; alert (t...

getSelection & surroundContents across multiple tags

Hi, I've got a script that changes the background colour of text that has been selected. However i'm encountering an issue when the text is selected across multiple elements/tags. The code that i've got is: var text = window.getSelection().getRangeAt(0); var colour = document.createElement("hlight"); colour.style.backgroundColor = "Y...

how do I get co-ordinates of selected text in an html using javascript document.getSelecttion()

I would like to position element above selected text. But I am not able to figure out the coordinates. var sel = document.getSelection(); if(sel != null) { positionDiv(); } Example: (image) ...

Range Selection and Mozilla

I would like to specify that firefox select a range. I can do this easily with IE, using range.select();. It appears that FFX expects a dom element instead. Am I mistaken, or is there a better way to go about this? I start by getting the text selection, converting it to a range (I think?) and saving the text selection. This is where I'm...

Javascript functions return lines of function code or "{[native code]}," what am I doing wrong?

I am writing some code to find the user selection in a contenteditable div, I'm taking my code from this quirksmode article. function findSelection(){ var userSelection; if (window.getSelection) {userSelection = window.getSelection;} else if (document.selection){userSelection = document.selection.createRange();} // For microsoft...

What is the easiest method to get the selection in input text field ?

How could I get the selected text in the following code ? I working with Firefox 3.6.3 (currently not interested in other browsers). HTML: <input id="my_text_field" type="text" /> <div id="log"></div> JavaScript: $("#my_text_field").select(function() { var selected_text = "Something selected"; // What should be here ? $("#log...

Need to set cursor position to the end of a contentEditable div, issue with selection and range objects.

I'm forgetting about cross-browser compatibility for the moment, I just want this to work. What I'm doing is trying to modify a script (and you probably don't need to know this) located at typegreek.com The basic script is found here. Basically what it does is when you type in characters, it converts the character your are typing into gr...

how to get selected text from iframe with javascript ?

how to get selected text from iframe with javascript ? ...

JavaScript getSelection() in certain pane?

hi, I'm trying to change the code of query-tool "Technology Explorer for IBM DB2", so only selected query will be run... I already got some help from the developer himself,but this only helped me find the right parts of code, not with coding new functionality... http://sourceforge.net/projects/db2mc/forums/forum/761212/topic/3821430 I...

How to get the coordinates of the end of selected text with javascript?

Hi, My problem is similar to this, but I need a way to get the coordinates of the right side of the selection with Javascript in Firefox. I made a small example to show what I mean: The code I got from the other post is the following: var range = window.getSelection().getRangeAt(0); var dummy = document.createElement("span"); range....

nodeName for selected text in Javascript

I have HTML which looks something like this: <span id="text"> <span class="segment" id="first">some text</span> <span class="segment" id="sec">bla bla</span> </span> and when user selects something, I want to identify which elements he had selected. If, for example, user had selected "text bl" I need both "first" and "sec" elements...