Blog posts
Categories
SharePoint

Open SharePoint List/Library Link in New Window

Why can’t a SharePoint list/library web part open links in a new window by default?

There are several workarounds, but here’s one easy way that seems to make sense to site owners. It adds some Javascript in an XML Web Part or Form Web Part that’s placed below the list/library web part (maybe, even at the bottom-most zone on the page, no?).

Why not use a Content Editor Web Part for the script? Well, that worked in SP2007, but to survive a migration from SP2007 to SP2010, the XML Web Part seems to be the way to go for small scripts like this, and if already in SP2010, the Form Web Part should do the trick.

The code looks for the name of the list/library on page load and adds the “target” attribute to the list web part’s table tag. So, say the list name in the current site is called “Links.” The code would look for that list name in the page source by it’s Summary attribute:

<script language="javascript" type="text/javascript">
  var tbl = document.getElementsByTagName('table');
    for(var i = 0; i < tbl.length; i++)
    {
      if(tbl[i].getAttribute("Summary") == "Links")
    {
    var anc = tbl[i].getElementsByTagName('a');
    for(var j = 0; j < anc.length; j++)
      {
        anc[j].setAttribute('target', '_blank');
      }
    }
  }
</script>

For more than one list/library on the page, the code is a bit different…

<script language="javascript" type="text/javascript">
  var tbl = document.getElementsByTagName('table');
  for(var i = 0; i < tbl.length; i++)
  {
    if(tbl[i].getAttribute("Summary") == "Links1"
    || tbl[i].getAttribute("Summary") == "Links2"
    || tbl[i].getAttribute("Summary") == "Links3")
    {
      var anc = tbl[i].getElementsByTagName('a');
      for(var j = 0; j < anc.length; j++)
      {
        anc[j].setAttribute('target', '_blank');
      }
    }
  }
</script>

2 replies on “Open SharePoint List/Library Link in New Window”

Thanks! But 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!

There are few more possible solutions, including JavaScript, JQuery, SharePoint Designer, List Schema Edit to SharePoint Link list – at SharePointDiary.com –
http://www.sharepointdiary.com/2011/02/sharepoint-link-list-open-in-new-window_21.html#ixzz2aWtiNarl

Leave a Reply

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