Making links open in a different window via jQuery

A common requirement I get when editing SharePoint search pages is making the links open in a different window/tab.
You could ofcourse go off and edit the xsl (which is quite easy by the way), but you could also look at jQuery to save the day once more.

Just add a content editor webpart to the results page, link to the jquery library and add this line:

$("a[href^='http://']").attr("target","_blank");

What this code does is add an attribute to all ‘a’ elements, the links. The attribute here is that it should open in a new window.

This code is not limited to the results page ofcourse, you could use it anywhere you want, even in non-SharePoint sites.

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.

%d bloggers like this: