Re: Is there any Javascript function or method that returns selected text?
Hello,
function getSel()
{
if (document.getSe lection) txt = document.getSel ection();
else if (document.selec tion) txt = document.select ion.createRange ().text;
else return;
document.forms[0].selectedtext.v alue = txt.replace(new
RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
}
I've found this function here:http://www.xs4all.nl/~ppk/js/selected.html
Kindest Regards,
Olexiy Merenkov
Re: Is there any Javascript function or method that returns selectedtext?
SpArKy wrote:[color=blue]
> 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[/color]
function ShowSelectedTex t()
{
if (window.getSele ction) // recent Mozilla versions
{
var selectedString = window.getSelec tion();
}
else if (document.all) // MSIE 4+
{
var selectedString = document.select ion.createRange ().text;
}
else if (document.getSe lection) //older Mozilla versions
{
var selectedString = document.getSel ection();
};
alert("The text you selected is \n'" + selectedString + "'");
}
Comment