Jump to content

Cookies do not respond in Google Chrome


Es_Dexter

Recommended Posts

Hello,

 

I have been developing a website for a school project in html, css and javascript. We'll be using the website for an interactive board game. One of the most important elements of the website are the scoreboard and the game questions. The game questions basically give a specific amount of points if correctly answered. The points will then be sent to the scoreboard, and saves it. The scoreboard makes use of cookies to save the data/reset the data.

 

And here comes my problem.. the scoreboard works great in Internet Explorer and Firefox, but not in Google Chrome. I have followed a tutorial on how to use cookies on w3schools (http://www.w3schools.com/js/js_cookies.asp) to help create the scoreboard. The cookies apparently do not work for me when I use Google Chrome, which is very unfortunate.

 

I would really like the website and cookies to be cross-browser compatible, and therefore I need some help. If anyone could help me out, then that would be great!

 

These are my scripts:

 

index.html

<!doctype html><html lang=nl><head>	<meta charset=utf-8>	<script src="cookie.js"></script>	</head><!--  dit is jouw hoofdpagina. zie ook commentaar op pag2.html	Script toevoegen op al je pagina's	bij je hoofdpagina bij de body onload=checkScore() toevoegen--><body onload=checkScore()>	<a href=pag2.html>Klik hier voor 10 punten</a><br>	<a href=pag3.html>Klik hier voor 5 punten</a>	<!-- deze div moet toegevoegd worden op de plek waar je de score 		wilt zien -->	<div id=score>	</div>		<!-- button om de scores op nul te zetten -->	<button onclick="reset()">Reset</button></body></html>

pag2.html

<!doctype html><html lang=nl><head>	<meta charset=utf-8>	<script src="cookie.js"></script>	<script>		var erbij=10;				function terug() {			createCookie("erbij", erbij);			window.location.assign("index.html");		}	</script></head><body>	<button onclick="terug()">Terug</button>	<button onclick="erbij=erbij+1">punten</button></body></html>

pag3.html

<!doctype html><html lang=nl><head>	<meta charset=utf-8>	<script src="cookie.js"></script>	<script>		var erbij=5;				function terug() {			createCookie("erbij", erbij);			//window.history.back();			window.location.assign("index.html");		}	</script></head><body>	<button onclick="terug()">Terug</button></body></html>

cookies.js

function checkScore() {		var s=getCookie("score");		if (s != "") {			erbij=getCookie("erbij");			if (erbij == "") {				erbij="0";			}			score= (parseInt(s)+parseInt(erbij)).toString();			createCookie("score", score);		}		else {			score="0";			createCookie("score", score);			erbij="0";			createCookie("erbij", erbij);		}		document.getElementById("score").innerHTML="Score: "+score;	}				function createCookie(name, value, days) {		var expires;		if (days) {			var date = new Date();			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));			expires = "; expires=" + date.toGMTString();		}		else {			expires = "";		}		var t=name + "=" + value + expires + "; path=/";		document.cookie = name + "=" + value + expires + "; path=/";	}	function getCookie(cname) {		var name = cname + "=";		var ca = document.cookie.split(';');		for(var i=0; i<ca.length; i++) {			var c = ca[i];			while (c.charAt(0)==' ') c = c.substring(1);			if (c.indexOf(name) == 0) {				return c.substring(name.length, c.length);			}		}		return "";	}		function eraseCookie(name) {		createCookie(name,"",-1);	}		function reset() {		document.getElementById("score").innerHTML="Score: 0";		eraseCookie("score");		eraseCookie("erbij");	}

All I need is the cookies to work in Google Chrome.

 

Thanks in advance,

 

Es_Dexter

Link to comment
Share on other sites

Check if the cookie is being set or not, you can use Chrome's developer tools for that. You should also check the console to look for Javascript errors. For the cookie, click on the Net tab in the developer tools and then click on the request for a page, like the index page. For the request, there will be tabs to show headers, the response, and cookies. You can check the cookies tab to see if the browser is sending cookies to the page. If so, then it might be a problem reading the cookie.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...