M
mIDO
Hello,
I have developed a script that change the font size in css, but only
the attribute "font-size" on the body tag, not change the entire
active stylesheet.
When i click to change the size
<a href="#" title="Change Font Size"
onclick="cambia_font_size(2);">A</a>
It works fine, but when i try to check the cookie to set the default
font size, it does not work.
The cookie stores the value correctly and i can read the value. The
problem is when i try to change the value:
document.getElementsByTagName("body")[0].style.fontSize=tam;
I have tried also writing this code at the end of the html document
but it doesnt work
<script type="text/javascript">inicializa_fontsize();</script>
What could happen?
Thanks
CODE
----------------------------
window.onload = function inicializa_fontsize() {
var valor=readCookie('fontsizeptgc');
if(valor!=null) {
//alert(valor);
cambia_font_size(valor); //cambia valor al hacer click pero no
"onload". revisar
}
}
function cambia_font_size(valor) {
var tam;
switch(valor) {
case 1:
tam='9px';
break;
case 2:
tam='11px';
break;
case 3:
tam='12px';
break;
default:
tam='11px';
break;
}
document.getElementsByTagName("body")[0].style.fontSize=tam;
createCookie('fontsizeptgc',valor,'7');
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca;
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 eraseCookie(name) {
createCookie(name,"",-1);
}
I have developed a script that change the font size in css, but only
the attribute "font-size" on the body tag, not change the entire
active stylesheet.
When i click to change the size
<a href="#" title="Change Font Size"
onclick="cambia_font_size(2);">A</a>
It works fine, but when i try to check the cookie to set the default
font size, it does not work.
The cookie stores the value correctly and i can read the value. The
problem is when i try to change the value:
document.getElementsByTagName("body")[0].style.fontSize=tam;
I have tried also writing this code at the end of the html document
but it doesnt work
<script type="text/javascript">inicializa_fontsize();</script>
What could happen?
Thanks
CODE
----------------------------
window.onload = function inicializa_fontsize() {
var valor=readCookie('fontsizeptgc');
if(valor!=null) {
//alert(valor);
cambia_font_size(valor); //cambia valor al hacer click pero no
"onload". revisar
}
}
function cambia_font_size(valor) {
var tam;
switch(valor) {
case 1:
tam='9px';
break;
case 2:
tam='11px';
break;
case 3:
tam='12px';
break;
default:
tam='11px';
break;
}
document.getElementsByTagName("body")[0].style.fontSize=tam;
createCookie('fontsizeptgc',valor,'7');
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca;
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 eraseCookie(name) {
createCookie(name,"",-1);
}