I'm trying to make two links on the left navigation open up into a new tab as they are external sites. It should be as easy as adding target="_blank" to their HTML element but when I wrote some jQuery to do this task the target gets added to the href of the link but it doesn't do anything to change the functionality.
Currently I have this code:
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push('openNewTab');
function openNewTab() {
jQuery('a[href$="?newTab"]').attr('target', '_blank');
};</script>
_spBodyOnLoadFunctionNames.push('openNewTab')
is the SP equivalent of document.ready
and it calls up my function openNewTab. jQuery is used instead of the usual $ to be sure that it doesn't mess with SP. Found this info here
This code works on any link that I add ?newTab
to within my page and they open in new tabs. However, it still does NOT work on links found in the navigation on the left of the page. Though it does add the target="_blank"
when inspected it displays as:
<a class="static menu-item ms-core-listMenu-item ms-displayInline ms-navedit-linkNode" tabindex="0" href="http://itgenwebapps.comp.dirsrv.com:8080/EnergyAppGUI/index.html?newTab" target="_blank"><span class="additional-background ms-navedit-flyoutArrow"><span class="menu-item-text">Fleet Dashboard</span></span></a>
Is there some out of the box solution to making these links go to a tab on a link to link basis? If there is or if someone has found how to make select links open in a new tab either would be much appreciated information.