There are a few alternatives to how one can get SharePoint Icon to always go to the home page of the root site. (By default, it goes to the home page of current site, so it is an issue if you are in a sub-site)
I found the following JavaScript method best and most robust among all the alternatives. The alternatives were updating the link on document load etc. but all those assume that SP will not update that link after your script has run (which it does in Search Center)
var hijackSiteIconLinkClick = function () {
$('.ms-siteicon-a').click(function (event) {
event.preventDefault();
event.stopPropagation();
window.location.href = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;
});
};
The above works for every type of subsite as it runs on anchor click event and not when JS thinks that SharePoint page is loaded.
PS: The code above assumes that you have JQuery loaded on the page prior to running this script
I found the following JavaScript method best and most robust among all the alternatives. The alternatives were updating the link on document load etc. but all those assume that SP will not update that link after your script has run (which it does in Search Center)
var hijackSiteIconLinkClick = function () {
$('.ms-siteicon-a').click(function (event) {
event.preventDefault();
event.stopPropagation();
window.location.href = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;
});
};
The above works for every type of subsite as it runs on anchor click event and not when JS thinks that SharePoint page is loaded.
PS: The code above assumes that you have JQuery loaded on the page prior to running this script
No comments:
Post a Comment