Since you dont want to modify the masterpage, the easiest & simplest method would be User Custom Actions
. Also, since this looks like a one time activity, you can write a console application using CSOM C#
to execute a javascript file on each page of the site collection. In the javascript file, we can add the code to modify the favico.
Try the below code:
UserCustomActionCollection collUserCustomAction = context.Web.UserCustomActions;
UserCustomAction userCustomAction = collUserCustomAction.Add();
userCustomAction.Location = "ScriptLink";
userCustomAction.Sequence = 9;
userCustomAction.ScriptSrc = "sitecollectionurl/SiteAssets/InsertFavIcon.js";
userCustomAction.Title = "Fav ico";
userCustomAction.Description = "Insert fav icon javascript";
userCustomAction.Update();
context.Load(userCustomAction);
context.ExecuteQuery();
Inside the InsertFavIcon.js
, the code to change favico would be as below:
var elem = document.getElementById('favicon');
elem.parentNode.removeChild(elem); //removes SharePoint OOTB favico
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = 'path-to-sitecoll/SiteAssets/favicon.ico';
document.getElementsByTagName('head')[0].appendChild(link);
Also, if you don't want to write a console application, you can write SharePoint hosted app or add code inside script editor/content editor webpart which will register the custom action. Code would be as below. This is a pure javascript based implementation:
function AddCustomActions() {
var clientContext = new SP.ClientContext();
var site = clientContext.get_web();
var UserCustomActions = site.get_userCustomActions();
var newUserCustomAction = UserCustomActions.add();
newUserCustomAction.set_location('ScriptLink');
newUserCustomAction.set_scriptSrc('sitecollectionurl/SiteAssets/InsertFavIcon.js');
newUserCustomAction.set_sequence(9);
newUserCustomAction.set_title('Favico');
newUserCustomAction.set_description('Insert favico javascript');
newUserCustomAction.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded(sender, args) {
console.log('New favico added to Site.');
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
AddCustomActions()
This will inject the javascript on each page. Also, keep in mind, this will not work on lists/libraries page(like allitems.aspx) if you have "New" list/libraries experience enabled as currently customizations are disabled on it.