Is there any Javascript function or method that returns selected text?

S

SpArKy

For e.g, I have a textarea and I want to get only the selected text
(the text I mark with the mouse).
Anybody?

ThX
 
D

DU

SpArKy said:
For e.g, I have a textarea and I want to get only the selected text
(the text I mark with the mouse).
Anybody?

ThX

function ShowSelectedText()
{
if (window.getSelection) // recent Mozilla versions
{
var selectedString = window.getSelection();
}
else if (document.all) // MSIE 4+
{
var selectedString = document.selection.createRange().text;
}
else if (document.getSelection) //older Mozilla versions
{
var selectedString = document.getSelection();
};

alert("The text you selected is \n'" + selectedString + "'");
}

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,574
Members
47,206
Latest member
Zenden

Latest Threads

Top