RadEditor for ASP.NET

Opening Link In A New Window When Clicked Send comments on this topic.
Handling Content > Opening Link In A New Window When Clicked

Glossary Item Box

 

The code below demonstrates how to get an access to the RadEditor document and go through all links in the editor when one submits the content. After that the code sets the link href attribute to #, as well as adds an onclick attribute with value window.open that opens it in a new window when clicked:

 

ASPX Copy Code
<script type="text/javascript">
function OnClientLoad(editor)
{
  
editor.AttachEventHandler ("RADEVENT_SUBMIT", function (e)
  {
       var links
= editor.Document.getElementsByTagName("A");
       
for (var i = 0; i < links.length; i++)
       {
           var link
= links[i];
           var href
= link.href;
           link.removeAttribute(
"href");
           link.setAttribute(
"href", "#");
           link.setAttribute(
"onclick", "window.open('"+ href + "',null,'height=500,width=700,status=yes,toolbar=no,menubar=no,location=no');return false");
       }
  }
 );
}
</script>
<
rad:RadEditor
   id
="RadEditor1"
  
OnClientLoad="OnClientLoad"
  
SaveInFile="true"
  
Runat="server">

  
Sample Content <a href="http://www.telerik.com">www.telerik.com</a> test <a href="http://www.yahoo.com">www.yahoo.com</a> test <a href="http://www.test.com/some.pdf">some.pdf</a>

</
rad:RadEditor>

 

You can use this approach to modify the attributes and events of all HTML elements in the editor content area.