Fixing SharePoint Promoted Link's New Tab Launch Behaviour
/There's a bug with Promoted Links web part in SharePoint 2013 and Office 365, and I have no idea how long it's been there. This post is about a simple Javascript hack that will fix it.
Story
Robert Crane [O365 MVP] found this one. Out of the blue, he asks me, hey why does the new tabs always open in the same tab. I thought, no way, it's always been working. So naturally, I tried it out and check the anchor tag. Expecting target="_blank"
TLDR
- Promoted Links spits out target="="_blank"" for who knows how long.
- Here's a fix.
SharePoint's Promoted Links Web Part
A quick introduction - this is the Promoted Links web part. If you have seen SharePoint 2013 or Office 365's SharePoint Online, then you have seen this web part. It is used everywhere for navigation.
Promoted Link is backed by a regular SharePoint list. Of interest, is the Launch Behavior column, which lets you decide what to do when a tile is clicked. You can navigate there Replacing Current Page, open in SharePoint's ModalDialog, or open in a New tab.
Open in New Tab
To prevent spammers running Javascript and creating lots of tabs when you visit a page, a browser gives no way for Javascript to create new tabs. The only way to do this, is natively in HTML, the tag looks like this: <a href="http://bing.com" target="_blank">B</a>
SP2013 (and Office 365) spits out this:
What would this do? Because target="="_blank"" is not a name that the browser knows about, it thinks, ah you want a new tab target, with that name. So the first click is OK, you navigate to that URL in a new tab.
The problem is that if you click multiple Promoted Tiles, they will all be loaded in the same tab, instead of different new Tabs.
IE11 seems OK
Curiously, IE11 creates new tabs. This however doesn't work on Edge.
Culprit
There seems to be a bug in sp.ui.tileview.js, adding target= into the attribute.
Fix
This can be fixed with a small bit of Javascript.
Edit the Page where your promoted list is giving you trouble. Say the Home Page. Insert "Embed Code" in a Web Part zone at the bottom of the page. (This short cut creates a Script Editor Web Part there)
Paste this bit of script.
<script language='javascript'> function fixATargetBlank(){ // using sharepoint's mQuery because I don't want to have // dependency on jQuery in this quick script m$("a[target][clickaction]").forEach(function(a){a.target="_blank";}); } // add this function to tell SharePoint to run it on load _spBodyOnLoadFunctionNames.push("fixATargetBlank"); </script>
The Script Editor will appear blank. That's OK. Save the page.
Result
The target is fixed to _blank. And clicking on the promoted links now opens them in separate new tabs, in all browsers.