Forum Moderators: open

Message Too Old, No Replies

How I can take a SELECTION?

help!

         

bandinopla

2:23 pm on Aug 26, 2004 (gmt 0)



I'm working in a RichtTextEditor and I whant to know, how can I get the user selection (of text) and pass it to a function like this:
...
alert ("you select this exact text" +?)
...

PD: I dont whant to know the selection type, I whan to know the exact content of a text selection.

Bernard Marx

2:50 pm on Aug 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This'll start you off with the IE side of things:


<head>
<script type="text/javascript">
// IE only!
function getSelection()
{
return document.selection.createRange().text;
}
// IE only!
function getSelectionHTML()
{
return document.selection.createRange().htmlText;
}
</script>
</head>
Somebody <b>please</b> select me.
<body>
<button onclick="alert(getSelectionText())">get text</button>
<button onclick="alert(getSelectionHTML())">get html</button>
</body>

(more IE-related)
Tutorial:
[course.com...]
MS:
[msdn.microsoft.com...]