Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Cute Editor for .NET
»
Re: Get Selected Text
Re: Get Selected Text
09-04-2009, 5:00 AM
Kenneth
Joined on 02-13-2008
Posts 3,886
Re: Get Selected Text
Reply
Quote
Hi humarashid,
Try the example below:
<%@ Page Language=
"C#"
%>
<%@ Register Namespace=
"CuteEditor"
Assembly=
"CuteEditor"
TagPrefix=
"CE"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head id=
"Head1"
runat=
"server"
>
<title>Untitled Page</title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<CE:Editor ID=
"editor1"
runat=
"server"
>
</CE:Editor>
<input type=
"button"
value=
"show selected message"
onclick=
"show()"
/>
</div>
</form>
</body>
</html>
<script type=
"text/javascript"
>
function show()
{
alert(getSelectedHTML());
}
var editor1=document.getElementById(
'<%= editor1.ClientID %>'
);
function getSelectedHTML(){
// get the active editor window
var editwin = editor1.GetWindow();
// get the active editor document
var editdoc = editor1.GetDocument();
var rng=
null
,html=
""
;
if
(document.selection && document.selection.createRange){
rng=editdoc.selection.createRange();
html=rng.htmlText||
""
;
}
else
if
(window.getSelection){
rng=editwin.getSelection();
if
(rng.rangeCount > 0 && window.XMLSerializer){
rng=rng.getRangeAt(0);
html=
new
XMLSerializer().serializeToString(rng.cloneContents());
}
}
return
html;
}
</script>
Regards,
Ken
View Complete Thread