This is probably a real NOOB question but I've been struggling to link a source file into my page code. I want to move the cookie code out of the page code.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="/SiteAssets/cookies.js" type="text/javascript"></script>
<script type="text/javascript">
// sets the cookie value and uses "/" path
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/";
}
$(document).ready(function () {
// Hide the site search box
$("#SearchBox").hide();
var red, yellow;
var siteurl = _spPageContextInfo.webAbsoluteUrl;
// Get score colors
$.ajax({
url: siteurl + "/_api/web/lists/getbytitle('GMP Defaults')/items",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
// Process cookies
},
error: function (data) {
alert("Error: "+ data);
}
});
});
</script>
This is being done in a subsite. The code is in the subsite's landing page in a Script Editor web part and cookies.js would be in Site Assets.
I've tried many different relative URLs and even put an absolute URL in the src statement and nothing seems to work.
Most of the examples doing something similar are using master pages and Style Library which have different relative URLs.
I thought I had a solution when I saw Mark Rackley's work using a content editor web part with the same subsite setup
<script src="../../SiteAssets/cookies.js" type="text/javascript"></script>
but that doesn't work either. I want to do the same thing with other common code in View and Form pages but if I can't it get to work here...