+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / TARGET in Links - Other Solutions Unclear

TARGET in Links - Other Solutions Unclear

14 posts, 0 answered
  1. Daniel Lewis
    Daniel Lewis avatar
    27 posts
    Registered:
    23 Sep 2009
    05 Nov 2009
    Link to this post
    So the Link Control in the WYSWYG editor for Generic Content does not support the TARGET attribute.  I see a bunch of articles discussing this.  The problem is that the solution discusses modifying the code, using a custom LinkManager.ascx - or something to that effect.

    I cannot seem to find this file.  All I want to do is be able to teach my content owners to put in a TARGET w/o going into Code View.  please provide an updated response.

    Also - along these same lines.  When in Generic Content preview mode, clicking a link to an external site creates havoc with the admin console.  Debug errors, etc.

    Thanks!

    Dan
  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    21 Nov 2016
    06 Nov 2009
    Link to this post
    Hello Daniel Lewis,

    The LinkManager inside the GenericContent's RadEditor is actually and aspx page. The page is located in ~\Sitefinity\UserControls\Dialogs\LinksDialog.aspx . This page acts as a container for the LinksDialog control embedded in the Telerik.Cms.Web.UI assembly in Telerik.Cms.Web.UI.Dialogs namespace. You can of course create your own versions of this control and page.

    Here is a simple solution:
    Open ~\Sitefinity\Admin\ControlTemplates\Generic_Content\ContentNewView.ascx if it does not exist you will have to map the ExternalTemplates you can download them from your Client.net account.
    Change the LinkManager javascript to look like this:
    Telerik.Web.UI.Editor.CommandList["LinkManager"] = function(commandName, editor, args) {
                                  var editorArgs = editor.getSelectedElement();
                                  if (!editorArgs.nodeName || typeof (editorArgs.nodeName) == "undefined" || editorArgs.nodeName != "A") {
                                      var sel = editor.getSelection();
                                      editorArgs = sel;
                                      editorArgs.Html = sel.getHtml();
                                      editorArgs.Text = sel.getText();
                                  }
     
                                  var myCallbackFunction = function(sender, args) {
                                      if (typeof (editorArgs.nodeName) != "undefined" && editorArgs.nodeName == "A")
                                          args.parentNode.replaceChild(editorArgs, args);
                                      else {
                                          var cloned = args.cloneNode(true);
                                          var div = args.ownerDocument.createElement("DIV");
                                          div.appendChild(cloned);
                                          var target = String(div.innerHTML);
                                          target = target.substring(3, target.length);
                                          target = '<a target="_blank" ' + target;
                                          alert(target);
                                          editorArgs.pasteHtml(div.innerHTML);
                                      }
                                  }
                                  editor.showExternalDialog(
                                 '<%= ((Telerik.Cms.Web.CmsPageBase)Page).ResolveCmsUrl("~/Sitefinity/UserControls/Dialogs/LinksDialog.aspx") %>',
                                 editorArgs,
                                 750,
                                 600,
                                 myCallbackFunction,
                                 null,
                                 'ImageLibraryDialog',
                                 false,
                                 Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
                                 false,
                                 true)
                              };

    Now each time a link is inserted a "target="_blank"" attribute will be appended.

    On the other problem with clicking a link to external site. Can you elaborate where is this link opened in the same window, new window etc.

    All the best,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Daniel Lewis
    Daniel Lewis avatar
    27 posts
    Registered:
    23 Sep 2009
    06 Nov 2009
    Link to this post
    Thanks for clarification for links.  I wish there was a way, like when I click the link button in the WYSWYG window I am writing this text in that shows TARGET as a dropdown option.  Having it default to blank is also not what we really want.

    As to clarification.  I have attached what happens.  It seems to be an IE only issue in PREVIEW mode of GENERIC CONTENT.  FF opens the new page, but doesn't throw all the browser errors.  Again - this only happens when TARGET is not set explicitly to _BLANK.  Then when I try to go back to HTML or DESIGN view.

    I have attached screenshots.
  4. Chris
    Chris avatar
    57 posts
    Registered:
    12 Nov 2008
    30 Nov 2009
    Link to this post
    If you're still looking for a solution, there's a knowledge base article that lets you add an "Open link in new window" checkbox to the link editor dialog: http://www.sitefinity.com/support/kb/sitefinity-3-x/how-to-extend-the-custom-radeditor-dialogs.aspx. It's for SF3.2, but still mostly accurate.

    Note that you have to add the following 2 lines in
    /Sitefinity/Admin/Themes/Default/CustomDialogs.css and
    /Sitefinity/UserControls/Dialogs/CustomDialogs.css:
    .dialogBox .checkBox input {widthauto;} 
    .dialogBox .checkBox label {displayinline;} 
    This is only if you're using Sitefinity 3.5 or higher I believe.
    I had actually posted these additions as comments to the mentioned KB article, but for some reason they're gone.

    LinksEditorDialog.ascx for Sitefinity 3.7 (I can't attach *.ascx-files...):
    <%@ Register Assembly="Telerik.Libraries" Namespace="Telerik.Libraries.WebControls" TagPrefix="sfLib" %> 
     
    <script type="text/javascript"
    var currentElement = document.createElement("a"); 
    var selectedHtml = ""
     
    function getRadWindow() //mandatory for the RadWindow dialogs functionality 
       if (window.radWindow) 
        { 
        return window.radWindow; 
        } 
        if (window.frameElement && window.frameElement.radWindow) 
        { 
         return window.frameElement.radWindow; 
        } 
        return null; 
     
    function initDialog() //called when the dialog is initialized 
       var clientParameters = getRadWindow().ClientParameters; //return the arguments supplied from the parent page 
     
       if (clientParameters.nodeName && typeof(clientParameters.nodeName) != "undefined" && clientParameters.nodeName == "A") 
       { 
           currentElement = clientParameters
               
           urlTxt = document.getElementById('<%= urlTextBox.ClientID %>'); 
           titleTxt = document.getElementById('<%= linkTextBox.ClientID %>'); 
           titleLi = document.getElementById("linkText"); 
           tooltipTxt = document.getElementById('<%= tooltipTextBox.ClientID %>'); 
           openInNewWindow = document.getElementById('<%= openInNewWindow.ClientID %>'); 
     
           if (currentElement.attributes["sfref"] != undefined) { 
            urlTxt.value = currentElement.attributes["sfref"].value; 
           } 
           else if (currentElement.href != "") { 
            urlTxt.value = currentElement.href; 
           } 
           if (currentElement.title != "") 
           { 
                tooltipTxt.value = currentElement.title; 
           } 
           if (currentElement.target != "" && currentElement.target == "_blank") { 
               openInNewWindow.checked = true
           } 
           if (currentElement.innerHTML != "") 
           { 
               htmlText = currentElement.innerHTML; 
               if (currentElement.childNodes.length > 1) 
               { 
                    titleLi.style.display = "none"
                    selectedHtml = htmlText 
               } 
               else 
               { 
                    titleTxt.value = htmlText
               } 
           } 
       } 
       else 
       { 
           titleLi = document.getElementById("linkText"); 
           titleTxt = document.getElementById('<%= linkTextBox.ClientID %>'); 
            
           //TELERIK 
           htmlText = clientParameters.Html; 
           if (clientParameters.Html.indexOf("<IMG ") != -1 || clientParameters.Html.indexOf("<img ") != -1) 
            selectedHtml = clientParameters.Html;                     
           pureText = clientParameters.Text; 
           titleTxt.value = pureText
            
           document.getElementById('linkURL').getElementsByTagName('input')[0].focus(); 
       } 
       requiredFieldsValidate(); 
     
    if (window.attachEvent) 
       window.attachEvent("onload", initDialog); 
    else if (window.addEventListener) 
       window.addEventListener("load", initDialog, false); 
     
    function insertLink() //fires when the Insert Link button is clicked 
       var closeArgument = currentElement
       urlTxt = document.getElementById('<%= urlTextBox.ClientID %>'); 
       titleTxt = document.getElementById('<%= linkTextBox.ClientID %>'); 
       titleLi = document.getElementById("linkText"); 
       tooltipTxt = document.getElementById('<%= tooltipTextBox.ClientID %>'); 
       openInNewWindow = document.getElementById('<%= openInNewWindow.ClientID %>'); 
     
       if (urlTxt) { 
        closeArgument.href = urlTxt.value; 
        if (urlTxt.value.indexOf("~/") == 0 || urlTxt.value.indexOf("[") == 0) { 
            closeArgument.setAttribute("sfref", urlTxt.value); 
        } else { 
            closeArgument.removeAttribute("sfref"); 
        } 
       } 
        
       if (selectedHtml != "") 
       { 
            closeArgument.innerHTML = selectedHtml
       } 
       else if (titleTxt && titleLi.style.display != "none") 
       { 
            closeArgument.innerHTML = titleTxt.value; 
       }    
        
       if (tooltipTxt && tooltipTxt.value != "") 
            closeArgument.title = tooltipTxt.value; 
     
       if (openInNewWindow.checked) { 
            closeArgument.target = "_blank"
       } 
       else { 
            closeArgument.target = ""
       } 
     
       var radWindow = getRadWindow(); 
       radWindow.argument = closeArgument
       radWindow.close(closeArgument); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page. 
     
    function beforeInsertLink(src, altText, title)  
        if (src != '') 
        { 
            urlTxt = document.getElementById('<%= urlTextBox.ClientID %>'); 
            titleTxt = document.getElementById('<%= linkTextBox.ClientID %>'); 
            if (urlTxt && titleTxt) 
            { 
                urlTxt.value = src
                if(titleTxt.value == "") 
                    titletitleTxt.value = title; 
            } 
        } 
        requiredFieldsValidate(); 
    </script> 
    <div class="ctrlProps" id="div1"
    <div class="ctrlContent"
    <div class="uploadPane"
    <class="mand">* Mandatory fields</p> 
    <h2>Insert a link</h2> 
     
    <div  class="dialogBox"
     
        <ol> <li id="linkURL"
            
                <asp:Label ID="Label1" runat="server" Text="<%$Resources:Url %>" AssociatedControlID="urlTextBox"></asp:Label> 
                <asp:TextBox runat="server" ID="urlTextBox" onkeydown="requiredFieldsValidate();" onkeyup="requiredFieldsValidate(); return false; " onfocus="requiredFieldsValidate(); return false; " onblur="requiredFieldsValidate(); return false; "></asp:TextBox> 
                <asp:Label runat="server" Text="<%$Resources:Or %>"></asp:Label> 
                <sfLib:ButtonSelector runat="server" ID="selectFromExistingLink" ButtonText="<%$Resources:SelectFromExisting %>" WindowNavigateUrl="~/Sitefinity/UserControls/Dialogs/PagesSelector.aspx" AssociatedControls="urlTextBox" /> 
                <class="example"><asp:Literal ID="Label2" runat="server" Text="<%$Resources:UrlExpl %>" ></asp:Literal></p
       
          </li> 
            <li id="linkText"
                <asp:Label runat="server" Text="<%$Resources:Text %>" AssociatedControlID="linkTextBox"></asp:Label> 
                <asp:TextBox runat="server" ID="linkTextBox" onkeydown="requiredFieldsValidate();" onkeyup="requiredFieldsValidate(); return false; " onfocus="requiredFieldsValidate(); return false; " onblur="requiredFieldsValidate(); return false; "></asp:TextBox> 
                <class="example"><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:TextExpl %>" ></asp:Literal></p
            </li> 
            <li> 
                <asp:Label ID="Label3" runat="server" Text="<%$Resources:Tooltip %>" AssociatedControlID="tooltipTextBox"></asp:Label> 
                <asp:TextBox runat="server" ID="tooltipTextBox"></asp:TextBox>           
                <class="example"><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:TooltipExpl %>" ></asp:Literal></p
            </li> 
            <li>   
                <asp:CheckBox runat="server" ID="openInNewWindow" Text="Open link in new window" class="checkBox"/>   
            </li>  
        </ol> 
     
    <runat="server" id="actionButtons" class="button_area bottom"
        <span class="CmsButLeft disabled ok" id="submitBtnDisenabled"><strong class="CmsButRight light">Insert</strong></span
        <href="#" onclick="insertLink();" style="display: none; " class="CmsButLeft ok" id="submitBtnEnabled"><strong class="CmsButRight light"><asp:Literal runat="server" Text="<%$Resources:Insert %>"></asp:Literal></strong></a> 
        <span class="cmsorlbl"<asp:Literal runat="server" Text="<%$Resources:Or %>"></asp:Literal> </span> 
        <href="#" onclick="getRadWindow().close();" class="cmscclcmd"><asp:Literal runat="server" Text="<%$Resources:Cancel %>"></asp:Literal></a
    </p> 
    <script type="text/javascript"
    var lURL = document.getElementById("linkURL").getElementsByTagName("input")[0]; 
    var lText = document.getElementById("linkText").getElementsByTagName("input")[0]; 
    var textLi = document.getElementById("linkText"); 
    var submitBtnEnabled = document.getElementById("submitBtnEnabled"); 
    var submitBtnDisenabled = document.getElementById("submitBtnDisenabled"); 
     
    function requiredFieldsValidate() { 
        if(lURL.value == "" || (textLi.style.display != "none" && lText.value == "")) { 
            submitBtnEnabled.style.display = "none"
            submitBtnDisenabled.style.display = "block"
        } else { 
            submitBtnEnabled.style.display = "block"
            submitBtnDisenabled.style.display = "none"
        } 
             
    </script> 
    </div> 
    </div> 
    </div> 
    </div> 

    Cheers,
    Chris
  5. PJulicher
    PJulicher avatar
    24 posts
    Registered:
    08 Apr 2010
    08 Apr 2010
    Link to this post
    Hi Chris,

    Great explanation!
    I cannot find the LinksEditorDialog.ascx. Does this need to be mapped from External TEmplates?

    Best regards,  Patrick
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Apr 2010
    Link to this post
    Hello PJulicher,

    Have you checked the following location ~/Sitefinity/Admin/ControlTemplates/Pages/Dialogs/LinksEditorDialog.ascx ?

    All the best,
    Ivan Dimitrov
    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.
  7. PJulicher
    PJulicher avatar
    24 posts
    Registered:
    08 Apr 2010
    08 Apr 2010
    Link to this post
    Hi,

    And sorry :-(. I must have been looking with my eyes closed.
    Is there any way to do the same thing when creating links to documents in a Document  Library? Is there an example of that as well? Documents now open in the same window, leaving the website to "disappear"!

    Best regards,  Patrick
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    08 Apr 2010
    Link to this post
    Hi PJulicher,

    Open and modify  as shown below Sitefinity/Admin/ControlTemplates/Libraries/Dialogs/DocumentEditorDialog.ascx

    function insertLink() //fires when the Insert Link button is clicked
        {
            var closeArgument = currentElement;
            selValue = document.getElementById('<%= selectedValueField.ClientID %>')
            editHolder = document.getElementById('<%= editHolder.ClientID %>');
            titleField = document.getElementById('<%= titleTxt.ClientID %>');
            targetLink = document.getElementById('<%= Target.ClientID %>');
            var uplImg = document.getElementById('<%= uploadedDocument.ClientID %>');
            closeArgument.href = selValue.value;
            closeArgument.innerHTML = titleField.value;
            if (targetLink.checked) {
                closeArgument.setAttribute("target", "_blank");
               
            }
            if (selValue.value.indexOf("~/") == 0) {
                closeArgument.setAttribute("sfref", selValue.value);
            } else if (selectedItem != undefined && selectedItem.unresolved) {
                closeArgument.setAttribute("sfref", selectedItem.unresolved);
            } else if (uplImg != undefined && uplImg.attributes["sfref"] != undefined) {
                closeArgument.setAttribute("sfref", uplImg.attributes["sfref"].value);
            } else {
                closeArgument.removeAttribute("sfref");
            }
     
            if(getRadWindow()){
            var radWindow = getRadWindow();
            radWindow.argument = closeArgument;
            radWindow.close(closeArgument); //use the close function of the getRadWindow to close the dialog and pass the arguments from the dialog to the callback function on the main page.
        }
    }

    add the following TextBox in the template

    <div class="uploadedImageData">
                   <asp:Label ID="Label1" runat="server" Text="<%$Resources:Title %>" AssociatedControlID="titleTxt"></asp:Label>
                   <asp:TextBox runat="server" ID="titleTxt"></asp:TextBox>
                   <p><asp:CheckBox runat="server" ID="Target" Text="<%$Resources:NewWindow %>" CssClass="check"/></p>


    Greetings,
    Ivan Dimitrov
    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.
  9. PJulicher
    PJulicher avatar
    24 posts
    Registered:
    08 Apr 2010
    14 Apr 2010
    Link to this post
    Hi Ivan,

    We chose another solution, but all is fine now. Thanks!

    Gr, Patrick
  10. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    27 Jan 2011
    Link to this post
    Hi Team,
    i've applied this solution, it work very well. So, at the moment I have a lot of links, in pages and news, that was added before this solution. There's a way to update these in bulk mode? I think maybe it's possible with a TSQL.
    Thank you for the help,
    Bachar
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    27 Jan 2011
    Link to this post
    Hi,

    For public controls like GenericContent you have to update [sf_CmsControlProperty] table.
    For backend - modules you have to update -[sf_CmsTextContent]

    Regards,
    Ivan Dimitrov
    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
  12. Bachar Zeidan
    Bachar Zeidan avatar
    67 posts
    Registered:
    01 Jul 2010
    27 Jan 2011
    Link to this post
    Ok, I know. But there are risk: what's the safer approach?
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    28 Jan 2011
    Link to this post
    Hi Bachar,

    Ok, you can use the API to update the content with parsing it and searching inside the HTML with Regular expression.

    You can use GetContent method to get all IContent items from different managers by using ContentManger class and passing the provider as a parameter.

    If this is not a shared content you have to loop through all pages and controls on them, get the control type, get the control for editing from the staged pages and change the content of the control.

    Regards,
    Ivan Dimitrov
    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
  14. Marc Myers
    Marc Myers avatar
    8 posts
    Registered:
    21 Apr 2010
    07 Jul 2011
    Link to this post
    Thanks very much.
Register for webinar
14 posts, 0 answered