Capturing a Text Selection : Text Selection « HTML « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » 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>

           
       
Related examples in the same category
1.Using the TextEdit Property
2.Using the elementFromPoint() Method
3.Get selected elememnt
4.Get selecte text in one paragraph
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.