Replace characters in url when clicking on Open Link context menu

4 posts, 1 answers
  1. Alien Interactive AB
    Alien Interactive AB avatar
    23 posts
    Member since:
    Jul 2004

    Posted 07 Nov 2019 Link to this post

    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") {
     
                     }
    }
  2. Answer
    Rumen
    Admin
    Rumen avatar
    14275 posts

    Posted 07 Nov 2019 Link to this post

    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.
  3. Alien Interactive AB
    Alien Interactive AB avatar
    23 posts
    Member since:
    Jul 2004

    Posted 07 Nov 2019 in reply to Rumen Link to this post

    Thanks Rumen, that works perfect after some minor modifications for our custom replace!
  4. Rumen
    Admin
    Rumen avatar
    14275 posts

    Posted 07 Nov 2019 Link to this post

    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.
Back to Top