Fix Broken Category Class Title in SharePoint 2010 Blog site
There is an old bug in SharePoint 2010 that surfaces to me from time to time: blog site category title doesn’t render correctly if it contains some funny foreign characters we Finnish like to use in our language.
The reason I’m writing this down right now is that I’ve got a case tomorrow at work where I have to fix this. This happens on a regular basis and I always write the fix from the scratch. Only this time, I don’t have to do it. I’ve got the CTRL-C / CTRL-V solution right here.
Buğra Postacı has blogged a solution that involves SharePoint Designer and manual labour earlier this year. As I’m not a fan of either I decided to use some nasty client script to hack the problem.
But let’s start with CSS!
Those question marks look weird in the category title, let’s get rid of the title by applying a CSS display: none. As we’re going to use JavaScript for our fix, it will take a few milliseconds to complete. I’m doing this CSS hiding to prevent flicker until the JS kicks in. Pure optional, that is.
The Javascript
I’m going to be using my favourite DOM manipulation library, jQuery combined with some vanilla JS but you can use whatever works for you. I’m just using the jQuery to find the element, so it is a bit of an overkill here but this is just an example.
First we need a helper function getUrlVars() to parse the URL and get to the hash. We will be using that to get the category name.
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
When the page is ready, we set the textual content of the category title to the decoded hash value and show the element (it was initially hidden with CSS). I’m using PageLoad() here because the page I’m using has a postback but once again you can use whatever works for you.
$j('h3.ms-CategoryTitleMonth').text(unescape(getUrlVars()['Name'])).show();
}
Which translates to:
That’s all there really is to it. Have fun.
Popularity: 4% [?]
This is awesome! Thank you for sharing informative content here. solar panel company
Thanks for helping Dover Handyman to fix their problem. ????