SharePoint 2013 Site Navigation Does Not Open in New Window

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):

opennewwindow

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).

6 Responses

  1. Pranav Sharma August 16, 2013 / 10:47 am

    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

    • Chris Poteet August 16, 2013 / 10:50 am

      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.

      • Pranav Sharma August 16, 2013 / 11:10 am

        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!

  2. chetna February 21, 2014 / 5:25 pm

    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.

  3. Gil May 19, 2014 / 12:24 pm

    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?

    • Chris Poteet May 19, 2014 / 12:27 pm

      Why can’t you disable MDS? It’s completely optional.

Comments are closed. If you have a question please contact me.