Click here to Skip to main content
15,886,519 members
Articles / Productivity Apps and Services / Microsoft Office
Tip/Trick

Open Links in a New Window in SharePoint 2010

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
6 Feb 2014CPOL1 min read 42.8K   11
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)


Written By
Software Developer (Senior) Sparkhound
United States United States
I have been a SharePoint Consultant for 7+ years. I have trained many developers on SharePoint. I have been to many clients creating intranets and extranets. I have worked all aspects from architecting to admin. My development background was in Game Development so I am very strong in DirectX and C++, as well as ASP.Net and C#.

Comments and Discussions

 
QuestionThis works great! Pin
Member 123292779-May-18 11:29
Member 123292779-May-18 11:29 
AnswerFinding the correct class Pin
Ted D Wagner11-Nov-15 6:26
Ted D Wagner11-Nov-15 6:26 
Questiona SP 2013 version of this Pin
Nick Leoncavallo11-Nov-15 4:36
Nick Leoncavallo11-Nov-15 4:36 
QuestionWhat am I doing wrong? Pin
Member 1104347628-Aug-14 6:35
Member 1104347628-Aug-14 6:35 
AnswerRe: What am I doing wrong? Pin
Ted D Wagner28-Aug-14 7:53
Ted D Wagner28-Aug-14 7:53 
GeneralRe: What am I doing wrong? Pin
Member 1104347628-Aug-14 8:57
Member 1104347628-Aug-14 8:57 
GeneralRe: What am I doing wrong? Pin
Ted D Wagner28-Aug-14 9:02
Ted D Wagner28-Aug-14 9:02 
GeneralRe: What am I doing wrong? SP 2010 Pin
rrealejo7-Oct-14 8:39
rrealejo7-Oct-14 8:39 
GeneralRe: What am I doing wrong? SP 2010 Pin
Ted D Wagner7-Oct-14 11:56
Ted D Wagner7-Oct-14 11:56 
GeneralRe: What am I doing wrong? SP 2010 Pin
rrealejo7-Oct-14 14:32
rrealejo7-Oct-14 14:32 
GeneralRe: What am I doing wrong? SP 2010 Pin
Ted D Wagner8-Oct-14 3:17
Ted D Wagner8-Oct-14 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.