Capturing a Text Selection : Text Selection : HTML JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » HTML » Text Selection »

 

Capturing a Text Selection



<HTML>
<HEAD>
<TITLE>Getting Selected Text</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var isNav4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion== 4)
var isNav4Min = (navigator.appName == "Netscape" && parseInt(navigator.appVersion>= 4)
var isIE4Min = (navigator.appName.indexOf("Microsoft"!= -&& parseInt(navigator.appVersion>= 4)
function showSelection() {
    if (isNav4Min) {
        document.forms[0].selectedText.value = document.getSelection()
    else if (isIE4Min) {
        if (document.selection) {
            document.forms[0].selectedText.value =
                document.selection.createRange().text
            event.cancelBubble = true
        }
    }
}
if (isNav4) {
    document.captureEvents(Event.MOUSEUP)
}
document.onmouseup = showSelection
</SCRIPT>
</HEAD>
<BODY>
<H1>Getting Selected Text</H1>
<HR>
<P>Select some text and see how JavaScript can capture the selection:</P>
<H2>ARTICLE I</H2>
<P>
text text text text text text text text text text text text text 
</P>
</HR>
<FORM>
<TEXTAREA NAME="selectedText" ROWS=COLS=40 WRAP="virtual"></TEXTAREA>
</FORM>
</BODY>
</HTML>

           
       



-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo HTML
» Text Selection