SharePoint Link list: Open in a New Window

In SharePoint, We can put any URLs in the Links list. Unfortunately, when clicking these links, the default behavior is for the page to open in the current browser window. That is, it does NOT open the page in a new instance of the browser. Often this is annoying, isn’t it?

How to open SharePoint link list item in a new window? Well, There are many ways to solve this issue:

Option 1: Site Column Approach

The Simplest solution is, enable the publishing feature, create a site column of “Hyperlink with formatting and constraints for publishing” type, add this site column to your new list. Now you will get an option to open in a new window! Here is how:

  • Step 1: Create a Site column of type “Hyperlink with formatting and constraints for publishing” (Site Actions >> Site settings >> Site columns >> Create)
  • Step 2: Add this site column to your new list (List Settings >>Add from existing). Now, You will get an option to specify whether it should open in new window.
sharepoint link list open in a new window

This can be used in SharePoint 2010 links list open link in a new window and in SharePoint 2007 also.

Option 2. You can use SPD to convert the link list to XSLT Data view and get into the code, find the tag <A href> and add an attribute target=”_blank”.

Option 3. You can edit the Schema file for the link list items to open in a new window. Here is how:

  • Open the schema file for the links list feature.  usually, is located at: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\LinksList\Links\schema.xml

In this file there should be two instances of the following:
 < Column Name =”URL” HTMLEncode =”TRUE” />< HTML ><! [CDATA[” > ]] ></ HTML >
Replace them both with this:
< Column Name =”URL” HTMLEncode =”TRUE” />< HTML ><! [CDATA[” target=”_blank” > ]] ></ HTML >

  • Then do the IISReset, and now all the links in your links lists will open a new browser window!

Option 4.  You can use jQuery to modify all links attribute, so that all links in SharePoint site, will open in new window.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript">
$('a[href$="/"]').attr("target", "_blank");
</script>

Option 5. You can Make Selected Links in a Links List Open in a New Window with Little JavaScript and content editor web part. Here is how:

  • when creating links in the Links List, add #openinnewwindow on the end of each link that you would like to open in a new window.
  • Add the content editor webpart, and place the following code in it:
<script language="JavaScript">
_spBodyOnLoadFunctionNames.push("PrepareLinks");

function PrepareLinks()
{
  //create an array to store all the anchor elements in the page 
   var anchors = document.getElementsByTagName("a");
  //loop through the array
  
  for (var x=0; x<anchors.length; x++) 
   {
      //does this anchor element contain #openinnewwindow?
       if (anchors[x].outerHTML.indexOf('#openinnewwindow')>0)
        {
           //store the HTML for this anchor element
           oldText = anchors[x].outerHTML;
           //rewrite the URL to remove our test text and add a target instead
           newText = oldText.replace(/#openinnewwindow/,'" target="_blank');
           //write the HTML back to the browser
           anchors[x].outerHTML = newText;
         }
     }
 }
</script>

If you want all of your external links to open in the new window you can make use of the below code:

<script>
 
var thisDomain = window.location.hostname;
var theLinks = document.links;
 
 for (i=0; i < theLinks.length; i++)
   {
    var thisLink = theLinks(i);
   if (thisLink.href.indexOf(thisDomain) == -1 && thisLink.href.indexOf("javascript") == -1)
     {
       thisLink.target = "_blank";
      //alert(thisLink);
     }
   }
</script>

Or You can use the jQuery Equivalent to make SharePoint 2010 link list open in a new window:

<script src="https://code.jquery.com/jquery-1.8.0.min.js"></script>

<script>
$(function() {
     $('a').filter(function() {
          return this.hostname && this.hostname !== location.hostname;
          }).attr('target','_blank');
});
</script>

Similarly, To open SharePoint Top Navigation Links in a New window, Refer: SharePoint Top Navigation Link: Open in New Window

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

20 thoughts on “SharePoint Link list: Open in a New Window

  • I need the other way round. I need my SharePoint to Not open in new tab/window. How to do that? Its in SharePoint 2013.
    Thanks..

    Reply
  • As a new SP user, the information was clear and worked great! Thank you so much.

    Reply
  • Only works on the first page ie. on the page that shows the first 30 items

    Reply
  • Really Great post and works great in SharePoint 2013

    Reply
  • Hello, thanks a lot for article. I used code for “openinnewwindow” in SP2013, it works but when I use Item limit with “Display items in batches of the specified size”, so it works only at first view:( Other solutions to open every all links in new window don´t work:( What can I do?

    Reply
  • Thank you so much! It’s really great solution!!!

    Reply
  • Thanks for the preparelinks function. Is there a way to style the window, i.e. ‘toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=no,resizable=yes,locationbar=no, titlebar=no, width=400,height=200,left=200,top=50’);
    thanks.

    Reply
  • Thank you!!! Not only have you provided a simple and direct answer, but, your site looks like one to review regularly… please keep posting regularly 😉

    Reply
  • It Works….. Thanks for this great solution!!!

    Reply
  • Thank you so much 🙂

    Reply
  • Thanks! Great post!
    I chose solution 5 for all external links and recommend adding the jQuery lib to a document library and referencing to it.

    Reply
  • Thanks for this. I used solution 5. Works great for my purposes – at least until I change the view of my list to groupings. My links no longer open in a new window until I remove the group view. How can I fix this?

    Reply
  • This is a way better solution than any of the others I have been searching. Thank you very much!

    Reply
  • Great no code solution in option 1. Thank you!!

    Reply
  • Excellent solutions! Thanks so much for sharing them.

    Reply
  • Thanks! This was very helpful.

    Reply
  • Running 2012 – not working for me- anything I should check? I checked the code and it still opens in the same window for me.

    Reply
  • Been looking at loads of long winded work arounds for this solution but this worked first time without any issues!! Thank You!!!

    Reply
  • THank you so much,,,

    Reply
  • Great help! Thank you. I’ve added your blog to my RSS feeder for more. -Arnie

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *