This is a migrated thread and some comments may be shown as answers.

Can all links be opened in a new window by default?

2 Answers 46 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 05 Jul 2010, 02:38 PM
Hi there,

My users are uploading HTML content via a RadEditor control on their personal page.  (They will be pasting content from a source with the Editor in Design Mode rather than entering HTML directly.)  I would like to set the RadEditor control so that any links they include in their content automatically have a target="_blank" attribute inserted (if not already present), or do something equivalent so that on the resulting page the links will be opened in a new window/tab (rather than taking the viewer away from my web-site).  Any suggestions?

All advice gratefully received,

Ed Graham

2 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 05 Jul 2010, 02:57 PM
Hi Ed,

You can set target="_blank" to all links in the content area when submitting the content with the script below:
<script type="text/javascript">  
function OnClientSubmit(editor)   
{                                                         
    var links = editor.get_document().getElementsByTagName("A");  
    for (i=0; i<links.length;i++)  
    {  
        var link  = links[i];  
        link.setAttribute("target", "_blank"); 
    }  
}  
</script>  
<telerik:RadEditor runat="server" OnClientSubmit="OnClientSubmit" ID="RadEditor1" >  
    <ImageManager ViewPaths="~/" UploadPaths="~/" />  
    <Content>  
        <a href="http://www.telerik.com">Telerik</a><br />sample content<br />  
 
        <a href="http://www.telerik.com">Telerik</a><br />sample content<br />  
 
        <a href="http://www.telerik.com">Telerik</a><br />sample content<br />  
 
        <a href="http://www.telerik.com">Telerik</a><br />sample content<br />  
 
        <a href="http://www.telerik.com">Telerik</a><br />sample content<br />  
 
    </Content>  
</telerik:RadEditor>  
<asp:Button ID="Button1" runat="server" Text="Submit" />  

You can also find useful information in these help articles:
http://www.telerik.com/help/aspnet-ajax/openinglinkinanewwindowondoubleclick.html
and
http://www.telerik.com/help/aspnet-ajax/openinglinkinanewwindowwhenclicked.html


Best regards,
Rumen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ed
Top achievements
Rank 1
answered on 05 Jul 2010, 03:31 PM
Great stuff, Rumen -- efficient as ever!
Tags
Editor
Asked by
Ed
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Ed
Top achievements
Rank 1
Share this question
or