Javascript cookies only work in FireFox
I've written this code to change some font formats in one of my websites I've made with joomla (and designed with css sculptor.
For some reason it only works in Firefox and I can't get my hand on where the error is. Does somebody know what's going wrong here?
function readCookie(name) {
var nameEQ = name + "=";
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,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function getFontSize(){
var size = readCookie("fontsize");
if (size== null) return "normal"; else return size;
}
(function($) {
function setFontSize (size)
{
if (size == "small")
{
$("#contentWrapper").css("font-size", "10px");
$("#contentWrapper h1").css("font-size","14px");
$("#contentWrapper h2").css("font-size", "12px");
}
if (size == "big")
{
$("#contentWrapper").css("font-size","14px");
$("#contentWrapper h2").css("font-size","16px");
$("#contentWrapper h1").css("font-size","18px");
}
if (size =="normal")
{
$("#contentWrapper").css("font-size","12px");
$("#contentWrapper h2").css("font-size","14px");
$("#contentWrapper h1").css("font-size","16px");
}
document.cookie="fontsize=" + size + ";max-age=" + (60*60*24*365) ;
}
$(document).ready(function(){
var size = getFontSize();
setFontSize (size);
$('a#smallFont').click(function(e){
e.preventDefault();
setFontSize('small');
return false;
});
$('a#normalFont').click(function(e){
e.preventDefault();
setFontSize('normal');
return false;
});
$('a#bigFont').click(function(e){
e.preventDefault();
setFontSize('big');
return false;
});
}); // document ready
})(jQuery)