Using the document.selection Object
<HTML>
<HEAD>
<TITLE>selection Object</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function processSelection() {
if (document.choices.process[0].checked) {
status = "Selection is type: " + document.selection.type
setTimeout("emptySelection()", 1000)
} else if (document.choices.process[1].checked) {
var rng = document.selection.createRange()
document.selection.clear()
}
}
function emptySelection() {
document.selection.empty()
status = "Selection is type: " + document.selection.type
}
</SCRIPT>
</HEAD>
<BODY>
<H1>IE selection Object</H1>
<HR>
<FORM NAME="choices">
<INPUT TYPE="radio" NAME="process" CHECKED>De-select after two seconds<BR>
<INPUT TYPE="radio" NAME="process">Delete selected text.
</FORM>
<P onMouseUp="processSelection()">
Text, Text, Text, Text, Text, Text, Text, Text, Text, Text, Text,
Text, Text, Text, Text, Text, Text, Text, Text, Text, Text,
Text, Text, Text, Text, Text, Text, Text, Text, Text,
Text, Text, Text, Text, Text, Text, Text,
Text, Text, Text, Text, Text, Text, Text,
Text,
</BODY>
</HTML>
Related examples in the same category