文本選擇window.getSelection

文本選擇window.getSelection
馬克- to-win:馬克 java社區(qū):防盜版實(shí)名手機(jī)尾號(hào): 73203。



例 1.8(文本選擇IEFF.html)
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <script type="text/javascript">
       function fun1(){

if(window.getSelection){//DOM,FF,Webkit,Chrome,IE10
alert("馬克-to-win:火狐c(diǎn)lick事件包括鼠標(biāo)點(diǎn)下和抬起兩個(gè)動(dòng)作,不抬起不算結(jié)束,所以可以選擇文本。 window.getSelection is "+window.getSelection);
selectionText = window.getSelection();
}else if(document.getSelection){//IE10
selectionText = document.getSelection();
}else if(document.selection){//IE6+10-
selectionText = document.selection.createRange().text;
}else{
selectionText = "";
}

           strlen = selectionText.toString();
           alert(strlen);
  //  alert(document.selection.createRange().text);
       }
   </script>
<body>
<body onclick="fun1();">
<p>Select this textsfsadfsdafsdagfsadgsagsadgfsd</p>
sdgsagsadgsafghgfhfh
gsadgsaghfghfhgfhf
sabhhfghgfhfghfh
gsfdghf
sdaggfhf
gdhfghdf
sdagdhg
</body>
</body>
</html>