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

Pasting HyperLinks from word or typing them.

3 Answers 71 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Isaac
Top achievements
Rank 1
Isaac asked on 29 Dec 2008, 08:28 PM
Hi, I would like to know how the 'Click Preview' event is fired on the client. I am using the RadEditor for a fairly large web application. I need to be able to change all HyperLinks to Open in New Window after User types them in and then clicks on 'Preview'. Also, what would be the best way to convert all HyperLinks to Open in New Window after pasteing from Word. I'm not sure why you would ever open an external hyperlink inside of the RadEditor because there is no way to 'Return' and all the tool bars get disabled. Thank you very much.

Isaac.

3 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Dec 2008, 07:37 PM
Hello Isaac,

Please, see the following help articles which could be helpful for your scenario:

http://www.telerik.com/help/aspnet-ajax/openinglinkinanewwindowwhenclicked.html

and

http://www.telerik.com/help/aspnet-ajax/openinglinkinanewwindowondoubleclick.html.

You can also implement a content filter that will set target="_blank" attribute to the link when switching to Html or Preview mode.

Greetings,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Isaac
Top achievements
Rank 1
answered on 31 Dec 2008, 12:41 AM
Hi, thanks for the response. I have tried the solutions you mentioned. I implemented a javascript object as a custom content filter, but there is no function to implement that is called when the user clicks on 'Preview' View. Second, there is no way that I can see to set all Links to open in a new window if the user creates one to open in 'same window' and then clicks 'Preview' View to click on the links. Also, there is no way that I can see to get all links to open in new window if the user is pasting from Word. If the user is typing new text into the RadEditor and creates a link, how could we set the link to open in new window when the user clicks on 'Preview' View? Thanks for your help. Again, I'm not sure why you would ever want to open a link in the RadEditor since there is no clear way to get back when the RadEditor is in a web form.
0
Tervel
Telerik team
answered on 05 Jan 2009, 05:36 PM
Hello Isaac,

In your case I suggest the following approach - it preserves the links' original target setting as specified by the user, but set target="_blank" when user switches to Preview mode

<script> 
 
function OnClientLoad(editor) 
{        
    editor.add_modeChange(function() 
    { 
        //Convert all links to have target = "_blank" when user is in preview mode. Keep existing setting and restore it when user switches back 
        var mode = editor.get_mode(); 
        var links = editor.get_document().getElementsByTagName("A"); 
         
        for (var i=0; i < links.length; i++) 
        { 
            var link = links[i]; 
            //Keep old setting, set target=blank 
            if (mode == Telerik.Web.UI.EditModes.Preview) 
            { 
                link.setAttribute("original_target",  link.getAttribute("target")); 
                link.setAttribute("target",  "_blank"); 
            } 
            else  
            {                
               var target = link.getAttribute("original_target"); 
               if (target) link.setAttribute("target",  target); 
               link.removeAttribute("original_target"); 
            } 
        }                 
    }); 
           </script>                       
 

Do not forget to set the OnClientLoad property e.g.

            <telerik:radeditor runat="server" ID="RadEditor1"  
            OnClientLoad="OnClientLoad" ... /> 


Best regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
Isaac
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Isaac
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or