469,640 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,640 developers. It's quick & easy.

Change CSS property onload

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[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 eraseCookie(name) {
createCookie(name,"",-1);
}

Mar 28 '07 #1
1 5756
Edited >>

It works fine, but when i try to check the cookie to set the default
font size AT ONLOAD, it does not work.
----

Mar 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert Mark Bram | last post: by
6 posts views Thread by Peter Afonin | last post: by
1 post views Thread by Mike | last post: by
reply views Thread by Jennyfer J Barco | last post: by
4 posts views Thread by Weston | last post: by
3 posts views Thread by BillyZ | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.