Try our conversational search powered by Generative AI!

Links in TinyMCE

Vote:
 

Hello, I have the following problem:

1. I add some text to a XhtmlString property

2. I select some part of it and click Insert/edit link

3. I select the "Page" radio button and put my product details page

4. I enter a query string with the ID of the item in the "Remaining url" section (e.g. ?id=123)

5. In "Open in" I select "Open the link in a new window".

My issue is that when clicking that link after publishing it doesn't open a new tab, it just sends me to that particular item but on the same tab. I believe the TinyMCE is ver. 2.10.1. Is there a fix for this or is it just not intended to be used that way? Thank you!

#278800
Apr 20, 2022 14:35
Vote:
 

Hey KaladinBG,

Is the target="_blank" attribute not being added to the link in the HTML? The 'Open in' values can be configured in the admin interface.

I was unable to reproduce the issue using package version 2.10.1 following your instructions. If the frames are configured correctly then possibly some custom javascript or other functionality is causing problems for you. Either way you can try upgrading to version 2.13.7 — which is currently the latest version supported for CMS 11 — to reduce the chance of any bugs.

#278985
Edited, Apr 22, 2022 0:23
Vote:
 

In case if you are looking for it to be there for all anchor tags within TinyMCE editor, Then you can use following extension method that will do it for all 

    public static class XhtmlStringExtensions
    {
        /// <summary>
        /// Parses the XhtmlString for Image tags and sets them to lazy load
        /// </summary>
        public static string FormatRichText(this XhtmlString html, ViewContext context)
        {
            // html is null when the TinyMce is not initialize (creating new block etc.)
            if (html == null) return string.Empty;

            // Load up Epi's HtmlHelper and ask it to render results
            var hh = new HtmlHelper(context, new ViewPage());

            string epiRenderingResult;

            using (var writer = new StringWriter())
            {
                hh.ViewContext.Writer = writer;
                hh.RenderXhtmlString(html);
                writer.Flush();
                epiRenderingResult = writer.ToString();
            }

            if (PageEditing.PageIsInEditMode)
                return epiRenderingResult;

            // once results are rendered, load up HtmlAgilityPack and have it parse results

            var doc = new HtmlDocument();
            doc.LoadHtml(epiRenderingResult);

            var anchors = doc.DocumentNode.SelectNodes("//a");
            if (anchors != null)
            {
                foreach (var item in anchors)
                {
                   item.SetAttributeValue("target", "_blank");
                }
            }

            var outerHtml = doc.DocumentNode.OuterHtml;
            return outerHtml; // return out the new resulting HTML
        }
    }
#279159
Apr 25, 2022 12:50
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.