クライアントイベントを使用できますか?JQueryのCaretプラグインを見ることができます:http:
//www.examplet.buss.hk/jquery/caret.php
// Get start position in textbox box with id="textbox1"
$("#textbox1").caret().start
// Get end position in textbox
$("#textbox1").caret().end
// Get selected text in textbox
$("#textbox1").caret().text
簡単なJavascriptソリューションもあります。
<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>
<form>
<input type="button" value="Get selection" onmousedown="getSelText()">
<form name=aform >
<textarea name="selectedtext" rows="5" cols="20"></textarea>
</form>
ソース: http: //www.codetoad.com/javascript_get_selected_text.asp