The example demonstrates how to attach an ondblclick (on double click) event handler to the editor content area, check whether the selection is an A tag and if it is to open it in a new window:
| ASPX |
Copy Code |
<script type="text/javascript"> function OnClientLoad(editor) { editor.AttachEventHandler ("ondblclick", function (e) { var sel = editor.GetSelection().GetParentElement(); //get the currently selected element var href = null; if (sel.tagName == "A") { href = sel.href; //get the href value of the selected link window.open(href, null, "height=500,width=500,status=no,toolbar=no,menubar=no,location=no"); return false; } } ); } </script> <rad:RadEditor id="RadEditor1" SaveInFile="true" Height="400px" OnClientLoad="OnClientLoad" Runat="server">
Sample Content <a href="http://www.telerik.com">Open Telerik.com</a> Sample Content
</rad:RadEditor> |
We can further enhance the example by programmatically setting a title attribute with "Doubleclick to open the link in a new window" value to all links in the content area. You can do that with the following code:
| JavaScript |
Copy Code |
|
var link = editor.Document.getElementsByTagName("A"); //get a reference to the links in the content area of RadEditor for (var i = 0; i < link.length; i ++) { link[i].setAttribute("title", "Double click to open the link in a new window"); } |
Here is the complete solution:
| ASPX |
Copy Code |
<script type="text/javascript"> function OnClientLoad(editor) { var link = editor.Document.getElementsByTagName("A"); for (var i = 0; i < link.length; i ++) { link[i].setAttribute("title", "Double click to open the link in a new window"); }
editor.AttachEventHandler ("ondblclick", function (e) { var sel = editor.GetSelection().GetParentElement(); var href = sel.href; if (sel.tagName == "A") { window.open(href, null, "height=500,width=500,status=no,toolbar=no,menubar=no,location=no"); return false; } } ); } </script> <rad:RadEditor id="RadEditor1" SaveInFile="true" Height="400px" OnClientLoad="OnClientLoad" Runat="server">
<A href="http://www.telerik.com"> Open Telerik.com</A> Sample Content <A href="http://www.telerik.com"> Open Telerik.com</A> Sample Content <BR><A href="http://www.telerik.com"> www.telerik.com</A>
</rad:RadEditor> |