Tuesday, January 3, 2017

Hashtag navigation in SharePoint 2013

From this thread:  I cant add a hashtag at the end of a url for a navigation item
(NYTom's answer)

//About the following block of code
//Because of SharePoint MDS, SP doesnt like appending data to the 
//querystring of a navigation item.
//If a navigation item has data appeneded like a ? or #, 
//it gets stripped off. I have contacted MS about this and this is by design
//To get around this, I have that when a navigation item 
//label startes with #, then the #gets stripped off and the url gets
//appended a # along with the label with spaces stripped off, 
//so the anchor tag will work. -- TJF
$anchorResults = $('a').filter(function() {
    var txt = $(this).text();

    return (txt.length > 1 && txt[0] == '#');
});

$.each($anchorResults, function (index, value) {
    var txt = $(value).text().substring(1);
    var href = $(value).attr('href') + '#' + txt.replace(/ /g, '');

    $(value).text( txt );
    $(value).attr('href', href);
});
//End Block

No comments:

Post a Comment