3

It appears I cannot configure a hyperlink column to open in a new window. I read in this post that you can concatenate a hard coded url with the title field of an item to achieve this. However, that doesn't quite do what I want.

I'd like to be able to use a calculated column to take the values of the Web field url and Web field description so I can display a column that shows ex: CNN but opens in a new window.

Is this possible using calculated columns and not jquery. Or is it even possible with some CSS in a content editor web part on the page?

5

There is a calculated column 'trick' where you return a number type but use regular string concatenation and an html 'a' tag and the item will show up for you as a link

Something like ="<a href='https://www.google.com?q='"&[searchColumn]&"'>click here</a>"

You should be able to add your target _blank attribute using the above.


EDIT: A more comprehensive explanation of this technique...

Okay, so if you need to do something like add a target="_blank" attribute or dynamically generate a URL based on other data a list item contains, you need to use a calculated column.

You have some choices here, but you cannot use the 'Hyperlink or Picture' column type to define any of the data because it is not supported in calculated column field values.

In the most general case, you can use a text column to define the link value then use a calculated column as the column that you actually display in a list view.

Say you have a text field called 'linkVal' where you enter in the URL for each list item that you want. It should contain a valid URL that you specify, but otherwise it won't have any other restrictions.

What I'm proposing above, is that in a scenario like this, you can use a calculated column to display a link to this URL, that will also have the target attribute set so that the link opens in a new window.

Your calculated column would have a formula value like this:

="<a href='"&[linkVal]&"' target='_blank'>Click Here</a>"

This could also be expanded if you included another field on each list item that could have a value for the text inside the a tag. Let's say you had an additional field called 'linkDescrip' -- then you could use a calculated column formula like this:

="<a href='"&[linkVal]&"' target='_blank'>"&[linkDescrip]&"</a>"

And the link's href value will take the linkVal column's value, and the description shown for the link will be the value in the linkDescrip column.

Remember to ensure that your calculated column is returning a number by selecting 'Number' after the prompt at the bottom of the column settings page labeled 'The data type returned from this formula is'. This is important, as data that is returned as a number will be calculated by the SharePoint server.

  • I put in ="<a href='https://www.google.com?q="&[Web]&"'>click here</a>" I get One or more column references are not allowed, because the columns are defined as a data type that is not supported in formulas. I noticed that the Web field was not listed under "Insert Column". So I put [Age] in its place and it went though. But all that happens is a link that opens https://www.google.com/?q= in a new window. I don't understand the google link part.. I want to create a hyperlink column in a list and have whatever's in that hyperlink open in a new window. Can you be more specific? – spex5 Aug 7 '14 at 20:57
  • @spex5 edited answer to provide a more comprehensive explanation of the technique involved – John-M Aug 8 '14 at 3:58
  • Thank you so much John-M ! This works perfectly, you just made my day. – Maelch Nov 18 '15 at 13:48
1

Maybe this will help anyone who doesn't want to use css or javascript magic and just use OOB SharePoint columns. For me multiline text field with enabled rich editing *including HTML) worked nicely. I just putted in as field value html generated like this:

private string GenerateUrlLinkForMultilineTextField(string url)
{
    return "<div class='ExternalClass2CBB4C914FA44F27B93A8D4336C4A307'>" +
            "   <div class='ms-rtestate-read ms-rte-embedcode ms-rte-embedil ms-rtestate-notify'>" +
            $"       <a href='{url}' target='_blank'>link</a>" +
            "   </div>" +
            "</div>";
}

Then simply assign:

newItem["URL"] = GenerateUrlLinkForMultilineTextField("http://somelink.com");

For our requirements we made this field readonly. Link worked like a charm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.