<head>
<script LANGUAGE="JavaScript">
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function showSelection(){
if (window.getSelection) {
alert(window.getSelection());
document.forms[0].selectedText.value=window.getSelection();
} else if (document.getSelection) {
alert(document.getSelection());
document.forms[0].selectedText.value=document.getSelection();
} else if (document.selection) {
alert(document.selection.createRange().text);
document.forms[0].selectedText.value=document.selection.createRange().text;
}
}
if (isNav) {
document.captureEvents(Event.MOUSEUP);
}
document.onmouseup = showSelection;
</script>
</head>
<body>
<P>
這些都是用來測試的文本,您可以用鼠標來選中,然后試一試選擇文本后產生的結構。
</P>
<form name="dataholder">
<textarea name="selectedText" rows = 3 cols=40 wrap="virtusl">
</textarea>
</form>
</body>