Howvever, I managed to fix this by this code. Please use this below coding for capturing the textbox selected value.
<**head>
<script type="text/javascript">
function GetSelectedText() {
var selText = "";
if (window.getSelection) { // all browsers, except IE before version 9
if (document.activeElement &&
(document.activeElement.tagName.toLowerCase() == "textarea" ||
document.activeElement.tagName.toLowerCase() == "input"))
{
var text = document.activeElement.value;
selText = text.substring (document.activeElement.selectionStart,
document.activeElement.selectionEnd);
}
else {
var selRange = window.getSelection();
selText = selRange.toString();
}
}
else {
if (document.selection.createRange) { // Internet Explorer
var range = document.selection.createRange();
selText = range.text;
}
}
if (selText !== "") {
alert (selText);
}
}
</script>
</head>
<body onmouseup="GetSelectedText()">
Some text for selection.
<br /><br />
<textarea>Some text in a textarea element.</textarea>
<input type="text" value="Some text in an input field." size="40"/>
<br /><br />
Select some content on this page!
</body>**
該代碼工作的Mozilla瀏覽器,只要選擇實際存在。你什麼時候調用這個代碼?幾乎可以肯定的是,在代碼被調用的時候,選擇並不存在。 – 2012-07-13 11:00:28