SharePoint 2013 Site Navigation Does Not Open in New Window Chris Poteet, August 14, 2013August 19, 2013 Every time you think you’ve seen it all with SharePoint another weird behavior comes along. A PM in my company expressed that a client’s subsites (that were based on the team site template) were not respecting the navigation setting (the structured navigation tool) to open links in a new window. All the setting does is add a target=”_blank” to the link. Here is what the setting looks like (from Site Settings – Navigation): From what I can tell, other site templates do not have this issue. In team sites, the following JS function is adding to the div above the global and local navigation, and it causes the target to be ignored: onclick="return AjaxNavigate$OnClickHook(event, this);" In the init.js you can see where it’s pointing to, but ultimately I can’t tell what the purpose of this is. All it seems to do is extend the URL to use hashes. Here’s an example of the type of URL it generates when clicking on a document library. http://server/teamsite/_layouts/15/start.aspx#//teamsite/Meetings/Forms/AllItems.aspx The only guess I have is that this is used maybe for the analytics engine that is tracking items by click for popularity rankings, but I’m not sure that’s exactly why. If it were, I’d imagine it would be used in other site templates as well. [See the update below] So, what about a fix? For that, I would simply remove the onclick event (which they shouldn’t be doing anyway, cf. unobtrustive JavaScript) using client-side scripting. Here’s an example with jQuery (if you have a custom master page make sure the library is referenced, or you could add a module if you don’t have a master page): $("div[id*='V4QuickLaunchMenu'], div[id*='TopNavigationMenu']").removeAttr("onclick") UPDATE: So it turns out this feature is part of the 2013 minimal download strategy enabled by default on team sites. When this feature is disabled the open in new window functionality is restored. To me, this is still a bug because the MDS should still honor the navigation functionality (or at least remove the option when the feature is enabled). Related Posts SharePoint User Interface fixjavascriptjquerynavigationsp2013
I think they do it to optimize page load times for their own pages. They put the url as a hash and then load the contents using ajax. This way the whole page doesn’t refresh and the user feels that its a faster experience. -My Own Opinion Reply
Yes I had that thought also, but at the end of the day it breaks core navigation functionality. I don’t know what you think, but it seems like a pretty inappropriate use of Ajax. Reply
I suppose an argument could be made for this only happening on MS Owned navigation elements. But then again, they should respect the option they themselves make available. I scream BUG REPORT! Reply
Yeah, it is misleading too, it shows that “Open in new window” but doesnt mean it. Asking changes in master page, css or java script is not user friendly. Reply
I’ve added the removeAttr(“onclick”) using JQuery but does seem to impact the behavior. Since this deals with MDS, is there a certain way it should be implemented. I’ve tried using _spBodyOnLoadFunctionName, ExecuteOrDelayedUntilScriptLoaded(xxx,init.js) and jQuery(document).ready(function)… but cannot seem to get the proper timing. I guess it is because of the MDS structure. Since I cannot turn MDS off, what is the proper technique to implement? Reply