3

Im running SharePoint 2013 with SP1. I need to add a hashtash to the url. As seen below. Everytime I add the hashtag and then Save the navigation settings, the hashtag gets removed.

Is this a bug and does anyone else have this issue?

Thanks.

Showing the hashtag I added

4

This is done purposly. SharePoint uses the hash for MDS (Minimal Download Strategy), and also # is a reserved character in URL:s (used for hash-based navigation)

  • I have MDS deactivated already on the site. What would be a way around this then, if you know of one? Also, hashed based navigation is what I am trying to do. – NYTom Jun 24 '14 at 13:55
  • I think for 2013 you should try to not use hash-based-navigation – Robert Lindgren Jun 24 '14 at 14:00
  • Then whats the alternative? In SharePoint there must be a way I can use a simple hashtag for navigation. – NYTom Jun 24 '14 at 14:04
  • 1
    I'm guessing you're trying to make use of in-page navigation. You can add some token for ex. "&hash&" within the url then use javascript to find that token and implement the in-page navigation jump. – Aveenav Jun 24 '14 at 14:38
  • Totally agree with the javascript approach. If you have navigation terms enabled, assign a page a custom friendly URL and once page loads, scroll to a specific ID element with jQuery's each() method and scrollTop. In my opinion this is more efficient because you can track all your custom URLs and there usage by SharePoint's Navigation Term links. No need to have hashes all over the place. – klewis Jul 11 '16 at 14:10
0

Just to share some code, this is how I got around the issue and it works perfectly. The code below would go inside a $(document).ready() function

//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
0

For people who are trying to use a hash within their URL parameter. One possible thing you can try is creating a custom sharepoint redirect page, that has a navigation term (friendly URL), that then redirects to your desired hash URL location. Works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.