Return to Snippet

Revision: 44088
at April 6, 2011 03:14 by kashif21


Initial Code
<script language=javascript>
function getSelText()
{
    var txt = '';
     if (window.getSelection)
    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
document.aform.selectedtext.value =  txt;
}
</script>
<input type="button" value="Get selection" onmousedown="getSelText()"> 
<form name=aform >
<textarea name="selectedtext" rows="5" cols="20"></textarea>
</form>

Initial URL

                                

Initial Description

                                

Initial Title
Cross Browser Text selection

Initial Tags
browser, text

Initial Language
JavaScript