How to open hyperlinks in a new window (or not)

When dealing with hyperlinks in SharePoint, users often point out the two following limitations:
– in a links list, there is no option to open a link in a new window.
– When using calculated columns to build URLs, the result is not displayed in a user-friendly way.

There are various methods to work around these limitations. Today I am going to show mine, which has the advantage of only using the SharePoint UI (no need for SharePoint Designer).

The issue

To understand the issue, let’s build a list of links pointing to the Microsoft SharePoint newsgroups:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.design_and_customization
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.development_and_programming
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.general
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.setup_and_administration

First, we create a custom list (Site Settings > Create > Custom list), call it “Microsoft newsgroups”, and add these four items:
sharepoint.design_and_customization
sharepoint.development_and_programming
sharepoint.general
sharepoint.setup_and_administration

The second step is to create a calculated column to build the links to the newsgroups:
Name: “URL”
Type: Calculated column
Formula:

= CONCATENATE ("http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.", [Title])

Let’s take a look at the result:

As expected, we have been able to build our URL, and the browser has interpreted it as a hyperlink. But the display is not very user-friendly. We’d prefer to just see the titles, for example “sharepoint.general”.

Building an user-friendly list of links

To achieve this result, I am going to apply to the above list my method: using calculated columns to write HTML.

This is the HTML I need (Title displayed, and on click open URL):
<DIV><a href=”URL”>Title</a></DIV>

So in SharePoint I am going to change the [URL] formula to this:

=CONCATENATE("<DIV><a href='","http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.",Title,"'>",Title,"</a></DIV>")

Now, the final touch: add the script to convert the string to HTML (how?), and you should now see this:

What is still missing is the option to open the link in a new window. Here are the steps:
– create an additional column in your list:
Name: “Open in new window?”
Type: Yes/No (check box)
– change the formula in the URL to this:

=CONCATENATE("<DIV><a href='","http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.",Title,IF([Open in new window?]=TRUE,"' target='_blank' ","'"),">",Title,"</a></DIV>")

Here is the final formula in clear (but you should actually copy/paste the above one):
=CONCATENATE(“<DIV><a href='”,”http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.”,Title,IF([Open in new window?]=TRUE,”‘ target=’_blank’ “,”‘”),”>”,Title,”</a></DIV>”)

As usual, feedback is welcome!

About these ads

87 thoughts on “How to open hyperlinks in a new window (or not)

  1. Pingback: EndUserSharePoint.com: How to create links, labels and coloring in a SharePoint list : End User SharePoint

  2. Does this work in WSS? I cannot copy your link as you indicate but I copied the text that is displayed. I get an error message, just wondering if it is ok with WSS?

  3. Yes, this works in WSS.

    Due to the page formatting, the end of the formulas is hidden. You should still be able to select the whole formula with a triple click.
    If you use the formula in clear at the end of the post, type it yourself in the calculated field, do not copy/paste.
    If you have any doubt, feel free to send me the formula you used(Christophe@PathToSharePoint.com) and I’ll double check it.

    • I am having the opposite issue. Our SP Site is opening a new window which doesn’t load as well as opening into outlook. I want the “open a new window” to not happen. I merely want it to open outlook. We are also having an issue with clicking on an internal pdf opening in a new window when I want it to stay local. How can I fix this and is it possible that it is at the server level?
      Thanks

      • Jeremy, it’s hard to tell and will depend on the link. In some cases the behavior is driven by a script, this will be difficult to change (and specific to each case).

  4. Christophe – When creating a link, I’d like to be able to use the [Name] column (file name), but [Name] is not an available column when creating the calculated string. Is there a way to access the [Name] column in the formula so that it won’t have to be hardcoded?

    =CONCATENATE(“”,Name,””)

  5. Sorry Mark, I am not aware of a way to use [Name] in calculated columns. Same issue for fields of type hyperlink, picture or lookup.

    If you don’t want to take the SharePoint Designer path, a trick would be to include some JavaScript in the upload form, that would capture the name and copy it to another field. This is risky, as changes happening outside the upload form (for example in explorer view) wouldn’t be captured.

  6. Hi, I had tried the method but couldn’t get it.
    Actually I’m trying to navigate my task records when I’m in the view/edit screen. I created a Calculated field with formula, =”http://sharepoint.teleatlas.com/sites/apac/GDPtest/Lists/Tasks/DispForm.aspx?ID=”&(ID-1), and I just want to display it as “Previous Rec” instead of the whole hyperline.

    Could I know how to do it?
    Thanks

  7. Hello

    Is it posible to remove the filtering row on top on the data rows? I’m using this trick to create a menu with links to other pages but I don’t like showing the name of the field as a filtering row. I don’t want people filtering the view.

    I’m using WSS 3.0.

    Best Regards

  8. Christophe, first of all thank you for your support.

    I’m using one links list for the whole site. The site has a lot of differente pages (it’s an Intranet) and each page has a link web part. In order to avoid a lot of links lists, I’ve just created one with some fields that work as filters. So when anyone creates a new page and needs a links list, the common links list is used and the user creates a new view for than page.
    In that case, the user shoudn’t be filtering, as what he’s seeing is the linsk for the specific page.

    Is it posible with Designer? Although I don’t have the tool I could ask some guys from other department to see if they can made the changes.

    Best regards

  9. Christophe, this does not seem to be working for me. I entered the following to test if it would work:

    =CONCATENATE(“TEST“)

    But all got was the following line in the Column.

    TEST

    I should expect only the word “TEST” in the column, correct? And if I press it, then it should should direct me to the url. Not working as expected though. Any help would be appreciated.

  10. So here is a question. When I set up new sites, on the home page I had a links list setup so users can add their own links and it would only display thier links, like a My Links view. When you add this link to the web zone it removes the column headers and creates a bulleted type list of the links. I created this custom list added it and it works perfectly, but I can not remove the column header, and I am not sure How I can make the view display as a bulleted list. Can this only be done with a links list?

  11. Larry, I also tried a “My Links” view in a department, but it never worked. People sticked to their browser bookmarks.
    Are you saying that you used the method described in this post? In this case, you should be able to get the bullets by adding a “li” tag in the formula.
    I often see questions about modifying the look of Web Parts (title background, remove buttons, hide column header), and I’ll publish a script for this. I have no magic trick, just regular CSS.
    What I usually do in such cases is create the view from scratch. For a list of links, I would for example:
    1/ grab the list content using the URL protocol:

    http://pathtosharepoint.wordpress.com/2008/09/24/using-the-rpc-method-via-the-url-protocol/

    2/ use Javascript to make it a drop-down menu, like here:

    http://pathtosharepoint.wordpress.com/2008/08/20/a-simple-drop-down-menu/

  12. Duh, I should have thought about the li tags. That is simple enough. Ireading the rest of your solution I guess I was making it harder that I should. Sorry now I will shut up. Thanks again. If you are in the states, have a great holiday!

  13. Hi…

    I want that my hyperlink should ALWAYS open in a new window. Also tell me if there is any way to HIDE a column… :)

    Plz let me know about this asap…

  14. Nice one but your article on this isn’t clear enough.
    You stated:
    First, we create a custom list (Site Settings > Create > Custom list), call it “Microsoft newsgroups”, and add these four items:
    sharepoint.design_and_customization
    sharepoint.development_and_programming
    sharepoint.general
    sharepoint.setup_and_administration

    What type of colmn fields did you create e.g single line of text,hyperlink etc….

    I have created a calculated column and i have pasted this sample link
    =CONCATENATE(“Previous record“)

    But if i do:
    =”http://wknt250:8182/sites/TeamSite1.aspx?k=”&Title
    I can get a link but i want a link like the one you created
    Thanks

  15. Hi Christophe,
    I followed exact your steps
    1.
    2.
    Formula:
    = CONCATENATE (“http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.”, [Title])
    And I got this error message:
    “The formula contains syntax error or is not supported”
    Did I miss something?

    • It’s due to the beginning blank space after the = sign
      i.e = CONCENATE … should be =CONCENATE

  16. Chelsea, I think the issue is with quotes formatting. I have corrected the post, note the subtle difference with what you pasted in your comment.

  17. Hi,
    Nice article ,if my list contains n number views,each views, i have to insert CEWP(java script code).is there any solution for this?

  18. sanjaya: the solution is to insert the script before creating the views. Once you have included a CEWP with the script in the main view, every new view you create based on the initial one will have the script included.
    Btw to facilitate later updates it is recommended to store the script in a document library and link to it from the CEWP.

    • Hi,

      We are having DailyTracker custom list to track daily project activities.In this list we have one column Department ( Type – dropdownlist ). Is it possible to open values appearing in Department dropdownlist as Lookup window similar to Person or Group window with option for user to select.

      I am new to SPS 2007. Please help me out.

    • Greg: I guess one solution would be to use a workflow to copy the hyperlink to a text column (but I haven’t tried).
      Another approach would be to use a script that will run on the page to identify the html hyperlink and extract the link URL. I did something similar once to extract the item id from the title column.

  19. Christophe – looks like this thread has been going for a bit –

    Glad I found it :-)

    I’m trying to simply copy the 1st part of the concat script and getting an error thrown back at me:

    My Formula:
    = CONCATENATE (“http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.”, [Title])

    Error:
    The formula contains a syntax error or is not supported.

    Using:
    WSS 3.0

    Any ideas?

  20. Good day Chris, first of all this is a very useful article.

    Here’s the scenario. I am building a pretty much like a records management system. For example I have created two lists, first is the List of Records, and the second one is the Request Form for the user to request any records.

    In the List of Records, I have created a calculated column named “Request this”. My suggestion is when user click the “Request this” link it will link to the (2nd list)Request Form’s New Item. Then user can fill in the details and then submit the form.

    Could u please help me in this area?

    Much Regards,
    Fayadh

      • Thank you very much for the quick reply.

        I have already solved the problem. Apparently, i use ‘&’ instead of ‘,’ for the CONCATENATE parameters and it works.

        Thanks for the tips Chris. I have followed u on twitter.

        Have a nice day! :D

  21. Christophe,
    Strange, but I was able to reference the ID in my calculated column that creates a URL string. My URL link needed to include a unique page to which the user should return based on Region. It works nicely, but now I want to wrap it in a hyperlink. I’ve been trying to follow instructions but get the “error in formula” message.

    Here is my URL output

    https://mycompany.com/Lists/Directory%20List%20%20Operations/DispFormGSO.aspx?List=e67ab1c7%2D8f74%2D4959%2Da0ef%2D7bea2e4e638a&ID=202&Source=https://gain.paegroup.com/Lists/Directory%20List%20%20Operations/KeyOA05.aspx

    and here is my formula…

    =CONCATENATE(“https://mycompany.com/Lists/Directory%20List%20%20Operations/DispFormGSO.aspx?List=e67ab1c7%2D8f74%2D4959%2Da0ef%2D7bea2e4e638a&ID=”,ID,”&Source=https://gain.paegroup.com/Lists/Directory%20List%20%20Operations/”,[Calc aspx page])

    I’ll continue banging at it. Is it required that I have a “Open in New Window” column?

  22. SharePoint won’t give you an error message, but still ID is not in the list of allowed fields in formulas.
    If you don’t need the “open in new window” part, just remove the IF from the formula.

    • Christophe,
      I appreciate the feedback. Got it to work. I broke out the calculated column into two calculated columns. However, I may have to try another approach using workflow and a hyper link field. Here is why…

      The list in which I am trying to display the link is in datasheet view. When in DS view, the code is displayed. Is there a workaround for this other than the workflow option that I found here? (link and steps below)

      Again, a BIG thanks.

      ===============================================

      http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/65d37c53-116a-4405-aa7a-1aeff26ad3ff/

      = = = = = = = = = = = = = = = = = = = = = =

      What I normally do:

      Create an optional hyperlink column in the list

      Create a worklflow with SharePoint designer that starts on Item Created and with no conditions

      In the workflow, create an “Store dynamic string” action and store into a new variable.

      The dynamic string can then consist of your URL with lookups for any parameters you need. (Example: “http://www.google.com?q=[%YourItem:YourField%], Look up in google”. The comma and subsequent text makes sure it fits nicely with the Hyperlink data structure, where the latter part of the string becomes the displayed text for the link

      Then add another action “Set field to value”, where you select the field from step 1 and for the value, the variable created in step 4.

      Job done.

      Proposed As Answer byKale Davis Wednesday, October 14, 2009 12:39 PM

      • To use a regular link list how can we set this computing field please kindly advice. I am unable to get it working

  23. Question, my [title] column contains spaces which seems to cut off the URL when the first space is reached. Is there any way to account for spaces?

    Great article btw.

  24. Hi Cristophe,

    I followed your instructions but I can still see the tags and the clickable part it the one with the url. Here’s my syntax:

    =CONCATENATE(““,idnumber,”“)

    Kindly correct.
    Thanks.

  25. Hello Christophe,
    These instructions are exactly what I’m looking for and I’ve got it *mostly* working. The URL is formatted exactly like I want and have verified it will work. The only part not working is the script to transform it from text to html. I copied your script found in the link (http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/), placed it in a text file and linked to it using the CEWP. Were there any changes you made to the script to get it to work on links instead of text formatting? Does the CEWP need to be last on the page or can it be first?
    Thanks for your help.

  26. hello ,
    Thanks for such article. i somehow cannot hide the long url that is diplayed in the calculated column. i have used custom new form for that particular list, and jqueries to create cascade dropdown.
    do u think that the already existing jquery is preventing this from working? i have even added a webpart (courtesy you), TextToHtml. even it has not helped.

    • Well, it should work if you followed the instructions in this post and included the TextToHTML.
      Test the customizations one at a time to try and isolate the issue. Sometimes the order may be important, I’d suggest for example to have TextToHTML before jQuery.

  27. Hi Christophe,
    Thanks for all your hard work. I love your solutions.
    I have an extra field to add to my Concatenation and I had it worked out fine.
    But when i go to try and enable the “Open link in new window” technique i just can’t get Sharepoint to accept my formula in URL column.
    I’ve included the working sample below and if you’re not too busy i would really appreciate the help to get the Pop-Up window working.

    =CONCATENATE(““,Status,”“)

    Thanks very much
    James

  28. Thank you for all the suggestions on this page. My problem is somewhat different. I would like to use your suggestion of “open in a new window” but change it to “open on side frame”. How do I get a list in one zone to open one of my calendar vies on a different zone on the same page.
    Thanks!
    KTT

    • While this can be done, I would not recommend to use my technique for this. You are mixing an item property with a page layout, and this is not consistent. Instead, I’d recommend to add a script to the page that will cnnect your hyprlinks to the frame.

  29. Thanks, most of it worked except for the last added column (Yes/No) which won’t show any checkboxes.???

  30. I tried your method, but field still dont looks like hyperlink, its just a simple text

  31. Great post! I have everything working except the CEWP for html conversion. I can get it working on any web pages that I create, but does this mean that I will never be able to convert to html when I’m viewing the list on the list page instead of another web page. If so, where do I put the CEWP. Thanks!

  32. After going over a few of the articles on your web page, I truly like your way of blogging.
    I book-marked it to my bookmark webpage list and will be checking back soon.
    Take a look at my web site as well and let me know how you feel.

  33. Hi Christophe:
    I am struggling with my formula.

    My list has these fields from which I need to create hyperlinks:
    [URL]
    [Title]
    [Open in new window?]

    I seem to be missing something in my formula. Would you see if you can spot my error?

    =CONCATENATE("<DIV><a href=’",[URL],[Title],IF([Open in new window?]=TRUE,"’ target=’_blank’ ","’"),">",[Title],"</a></DIV>")

    Thanks-

    Charlie Epes

  34. This technique was working flawlessly in our SP2007 environment, however since the upgrade to SP2010 the calculated field is once again showing as raw data (<a href…

    Is there something in the java script that needs to change to make this work in SP2010?

    • Depending on your view options, the old code might not work in SP 2010. I’d recommend that you take a look at the posts published in 2010, where I shared some workarounds for SP 2010.

  35. Pingback: SharePoint Calculated URL Column. | Tjen Sharepoint Blog

  36. There are many possible solutions to make SharePoint Links to open in new window. Simple and easiest solution is: Create a Site column of “”Hyperlink with formatting and constraints for publishing” type and add it in your list, which enables you to specify “Open in New Window” Option!

    Find the all possible solutions, including JavaScript, JQuery to SharePoint Link list – Open in a New Window at: http://www.sharepointdiary.com/2011/02/sharepoint-link-list-open-in-new-window_21.html#ixzz2aWqzWgLE

    • Thanks for sharing the link. Funnily the article you are mentioning misses the solution presented in this post :-)
      The “Hyperlink with formatting and constraints for publishing” is definitely an interesting choice, unfortunately it is not always available.

  37. Hi Christophe! I’d like to create a calculated URL – but based on an existing column which is a hyperlink. (cannot refer to column of type hyperlink when building formula for calculated column) – probably some workflow thing required, huh?

    • Because of the limitations with hyperlink columns, I usually prefer to store links in a simple text field.You are right, you could use a workflow to copy the link to a text field, but it’s a heavy workaround.

  38. Cristophe

    I have been playing with this on a SharePoint 365 site. The original calculated column technique generates the HTML fragment as described, but displays the raw HTML instead of a clickable link. However, if I change the formula data type to “Number (1, 1.0, 100)”, instead of “Single line of text”, the link works. Just one gotcha though, the column is right-aligned.

    I got the idea to try a Number column from:

    http://sharepointwijzer.nl/sharepoint-blog/tech/icc-html-calculated-column-sharepoint-view/

    • Right, this number trick is also mentioned in the comments on this blog. I am not advertising it though, as it’s obviously a bug and I would expect Microsoft to fix this behavior in the future.
      The approach I recommend in SP 2013 / Office 365 is to rely on Client Side Rendering. I posted an article with sample code a couple months ago.

  39. Hi, it works perfectly!

    I juste have an issue with the “Open in new window” part. The formula is correct, it’s rendered as a link in the list, but it doesn’t open it in a new window, even with the yes/no column, the IF and [open in new tab?]=TRUE..

    Can you help me? Here is my formula :

    =CONCATENATE(““,[myColumnToConcatenate],”“)

    I use MOSS (SharePoint 2007), and I do have followed all the steps.
    I’m familiar with this stuff since I used yours “How to” for the Color Parts too :)

    PS: The formula is invalid if I remove the [myColumnToConcatenate]’s brackets.
    I know there is something, but i don’t see it, maybe an “other eye” will help me.

  40. Hi Christophe,

    I have the following fields in a custom list:

    “Title” – Single Line of Text, Required, Non-unique values, 255 chars, Default text (not used)
    “SC_URL” (Site Collection URL) – Single Line of Text, Required, Non-unique values, 255 chars. Contains the FQDN of the Site Collection
    “Site Settings” – Calculated column, data returned is Number.
    Formula for “Site Settings” is:
    =CONCATENATE(“<a href='[SC_URL]”,”/_layouts/settings.aspx”,”‘ rel=”nofollow”>”,”Site Settings”,”</a>”)
    – Sample value in “SC_URL” is http://webapplication1.company.com/sites/sitecollection
    – The list I’m using this in is in a different web application (http://webapplication3.company.com) than the sample value (http://webapplication1.company.com)
    – The anticipated result is http://webapplication1.company.com/sites/sitecollection/_layouts/settings.aspx
    – The resulting URL is http://webapplication3.company.com/sites/sitecollection/int/SPC/Lists/SCM/%5BSC_URL%5D/_layouts/settings.aspx

    Any idea why this column is picking up my current webapp/managedpath/sitecollection/site/lists/listname instead of the URL in the Sample Value?

    Thanks in advance for your help, all your solutions have been a great value to my development activities!

    Best Regards,

    Chris

Comments are closed.