I am trying to write a script in Javascript that enables or disables other scripts based on the value of a cookie. I'll figure out how to set the cookie separately so I am just hardcoding for the moment.
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./script.js"></script>
<script class="GA" src="./scriptga.js"></script>
</body>
</html>
script.js (pseudo code as I dont know what way to do it):
var mycookie = 1
// enable script
if (mycookie=1) {
enable script with class="GA";
console.log("script enabled");
}
// disable script
else if (mycookie=2) {
disable script with class="GA";
console.log("script disabled");
}
// disable script
else {
disable script with class="GA";
console.log("script disabled");
}
scriptga.js:
console.log("script loaded");
Any help would be greatly appreciated as I have been at this for nearly 6 months on and off with no joy. I dont mind adding jquery or some other too to achieve this.