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

Replace characters in url when clicking on Open Link context menu

3 Answers 47 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Alien Interactive AB
Top achievements
Rank 1
Alien Interactive AB asked on 07 Nov 2019, 07:21 AM

Hi,

I have found a issue when a user opens a link by rightclick in the editor and then "Open Link" due to our customformated links with $* characters. 
I am trying to find a way to replace this characters before the link is opened.

Successfully catched the event in OnClientCommandExecuting but I guess it is to late there..

function OnClientCommandExecuting(editor, args) {
                 if (args.get_name() == "OpenLink") {
 
                 }
}

3 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 07 Nov 2019, 09:06 AM

Hi Martin,

Thank you for your question and for sharing your scenario!

You can override the OpenLink command as shown below:

        <script>
            function OnClientLoad(editor) {
                Telerik.Web.UI.Editor.CommandList.OpenLink = function (commandName, editor, commandArgs) {
                    var $T = Telerik.Web.UI;
                    var $Editor = $T.Editor;
                    var linkCmd = new $Editor.InsertLinkCommand(commandName, editor.get_contentWindow(), null, editor);
                    var selectedLink = linkCmd.getCurrentFormattedAncestor();
                    debugger
                    if (selectedLink) {
                        window.open(selectedLink.href || "about:blank", "_blank");
                    }
                }
            }
        </script>    
        <telerik:RadEditor runat="server" id="RadEditor1" OnClientLoad="OnClientLoad">
            <Content>
                <a href="http://www.telerik.com">Telerik link</a>
            </Content>
        </telerik:RadEditor>

The link href is returned by the selectedLink.href property and you can modify it with the replace JS method.

Please don't forget to remove the debugger :)

Keep me in touch!

Best Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alien Interactive AB
Top achievements
Rank 1
answered on 07 Nov 2019, 11:27 AM
Thanks Rumen, that works perfect after some minor modifications for our custom replace!
0
Rumen
Telerik team
answered on 07 Nov 2019, 04:35 PM

Perfect! Glad to be of help :)

 

Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Editor
Asked by
Alien Interactive AB
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Alien Interactive AB
Top achievements
Rank 1
Share this question
or