Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / Office

Open Links in a New Window in SharePoint 2010

5.00/5 (1 vote)
6 Feb 2014CPOL1 min read 43.8K  
Using JQuery to modify a list anchor tag to open in a new window.

Introduction

As a SharePoint admin or developer, the question I get asked most often is why do my links not open in a new tab, or how can I open my links in a new tab. The current functionality removes the user from their page, and makes it difficult to navigate back to previous content, especially if there is a custom master page. This solution is quick and an easy way to enhance the functionality of a Link List by using JQuery and a Content Editor Web Part.

Background

Since Microsoft thinks SharePoint users only open forms to view and click links, the functionality was not added to let the user select the ability to open links in a new window, even though links opened in a form, will open a new window. This issue causes the user's ability to navigate back to a previous page to be lost resulting in multiple back button clicks or re-loading of a home page.

Using the Code

I come across this issue quite frequently with clients as a consultant, I wanted to add the tip for everyone to use. Place a content editor web part at the bottom of the page and just cut and paste the code into it. Be sure to change the Chrome style to none.

JavaScript
<script type="text/javascript">
$(document).ready(function(){
$('.s4-ba a').attr('target', '_blank');
});</script> 

The class s4-ba is a reference to the content area where the web part resides, making all links in that area open in a new window. This code leaves the quick launch and top navigation untouched. This is a quick way to make your client happy with no customization.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)