By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,602 Members | 973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,602 IT Pros & Developers. It's quick & easy.

Change CSS property onload

P: n/a
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
Share this Question
Share on Google+
1 Reply

P: n/a
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.