SaaS CMS has officially launched! Learn more now.

How to open a URL property link in a new window?


I have this property:

public virtual Url Link { get; set; }

I want it to have an option in CMS to be able to open in new window,

How can I do it?

Please help

Aug 26, 2020 13:30

Use LinkItemCollection instead of Url.

public virtual LinkItemCollection LinkItem { get; set; }

Aug 26, 2020 13:59


I can't use LinkItemCollection. Please suggest if you have some other option.

Aug 26, 2020 14:02

I think what you can do the best is to have a SelectionFactory in place. That will act as the link should open in a new window/not.

Step 1

 public class LinkItemTarget : ISelectionFactory
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
            return new ISelectItem[]
                new SelectItem(){Text = "", Value = "" },
                new SelectItem(){Text = "Open the link in a new window", Value = "_blank" },
                new SelectItem() { Text = "Open the link in the whole window", Value = "_top" },

Step 2 - Decorate it on a different property specifically for links

        [Display(Name = "Block Link Target", Description = "target for the Link", GroupName = SystemTabNames.Content, Order = 11)]
        [SelectOne(SelectionFactoryType = typeof(LinkItemTarget))]
        public virtual string BlockLinkTarget { get; set; }

Step 3 - Using it on the page where your link is - 

    var linkTarget = !string.IsNullOrEmpty(Model.BlockLinkTarget) ? string.Format("target={0}", Model.BlockLinkTarget) : string.Empty;
 <a href="someLinkUrl" @Html.Raw(linkTarget)>.......</a>

The target in step 3 would set them to be the value that you choose from Episerver.

Hope it helps.

Aug 31, 2020 10:30

Hi Tanvi

Episerver recently introduced LinkItem in the Episerver Lab-On

Hopefully, it solves your problem.

Sep 01, 2020 2:33
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.