Open termbased navigation links in new window in SharePoint 2013


Term based navigation has been greatly improved in SharePoint 2013, but sometimes you want to open navigation URLs in a new window. However, the term store does not offer such a property so we'll solve it using JavaScript instead.

In the masterpage element add this script:

script language="JavaScript"

// Adding an entry to _spBodyOnLoadFunctionNames array so the function runs on pageLoad
_spBodyOnLoadFunctionNames.push("rewriteNavigationLinks");

function rewriteNavigationLinks() {
 // collecting anchors
 var anchorArray = document.getElementsByTagName("a");
 for (var x=0; x0) 
  {
   oldUrl = anchorArray[x].outerHTML;
   // adding target attribute
   newUrl = oldUrl.replace(/#targetnewwindow/,'" target="_blank');
   anchorArray[x].outerHTML = newUrl;
  }
 }
}
/script

Then in the term store append "#targetnewwindow" on the link to activate the specific link.

E.g.
http://intranet.foo/somepagename.aspx?pid=000#openinnewwindow

Comments

Popular posts from this blog

Power Pages Manifest Explained related to Collaborative Development and ALM

Exploring the Power of Variables in Liquid and Power Pages

Create an interactive HTML5 Canvas using event handlers.