1

how i can get (if)any text is selected in textbox and i want to get it in any variable of javascript.... specifically for Mozilla firefox...? the above description is not enough so let me give completely the definition.. My Extension of firefox is an Extension that double clicks any word from the webpage and finds its possible meaning from database... so user can even write anything in Textbox and double click the same for finding its meaning.. so please do suggest any way to complete selection from textbox's selected text....? in addition i am already using dblclick event handler so dont suggest that solution.... Also the problem is that the web page can be any site's webpage so even the textarea or any control is specific tho that page how could i slice the text from it than ...Thanxx in advance....

asked Feb 9, 2011 at 4:10
1

2 Answers 2

0

You can use document.getSelection() which returns a selection object containing the currently highlighted text in the document. However, calling it at the right time can be tricky. You can't do it from an onclick handler on a button, for instance, because by the time the onclick handler fires, the selection's focus has been removed from the text and moved to the button.

answered Feb 9, 2011 at 4:20
Sign up to request clarification or add additional context in comments.

1 Comment

i have used Document.double click and document.getSelection is not working
0

Use the selectionStart and selectionEnd properties e.g.

var selectedText = textbox.value.slice(textbox.selectionStart, textbox.selectionEnd);
answered Feb 10, 2011 at 0:33

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.