I have a js script and I want to apply it on a whole SP site. I inserted a content editor webpart on the start page and it works fine, but now i want to apply it on the whole site. Do I have to go through every page and insert a content editor webpart with the lines I need, or is there way to put it on one place and apply it on the whole site?
script.js:
$(function () {
getUser();
});
function getUser() {
var clientContext = new SP.ClientContext();
var web = clientContext.get_web();
var user = web.get_currentUser();
clientContext.load(user);
clientContext.executeQueryAsync(function(){
var leftNav = document.getElementById("DeltaTopNavigation");
leftNav.innerHTML += "<p>User:" + user.get_title() + "</p>";
//document.write("<p>User:" + user.get_title() + "</p>");
}, function(){alert(":(");});
}
and i calling it with this code in the content editor/seattle.master:
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/{PATH}/jquery-latest.min[1].js"></script>
<script type="text/javascript" src="/{PATH}/script.js"></script>