/    Sign up×
Community /Pin to ProfileBookmark

help with cookies!!

Ok, I have a script where the user can change the text size of the page. but, this changes as soon as they go to another page. how can i intergrate a cookie to be set so that the text size stays the same? here is the script (from dynamicdrive.com)

//Specify affected tags. Add or remove from list:
var tgs = new Array( ‘td’, ‘a’, ‘b’, ‘p’, ‘input’, ‘iframe’, ‘font’ );

//Specify spectrum of different font sizes:
var szs = new Array( ‘xx-small’,’x-small’,’small’,’medium’,’large’,’x-large’,’xx-large’ );
var startSz = 1;

function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;

sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;

if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

cEl.style.fontSize = szs[ sz ];

for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}

}

ENDS

After that, the controls are:

<a href=”javascript:;” onClick=”ts(‘cz’,1)”>Larger
Font</a> | <a href=”javascript:;” onClick=”ts(‘cz’,-1)”>Smaller
Font</a>

ts = text size
cz = css/id element where the text size will change
1, -1 = how the text will change!!

Thanks!? ? ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@theBody44May 25.2004 — Your code is a little strange in there is redundancy in some variables, but since I'm unsure of the entirety of your code, I stayed true to it's format. This should work for you.[CODE]<script>
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'td', 'a', 'b', 'p', 'input', 'iframe', 'font' );

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz;
var d = document,cEl = null,sz,i,j,cTags;

function ts( trgt,inc ) {
if (!document.getElementById) return

sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;

if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

cEl.style.fontSize = szs[ sz ];

for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
var exp = new Date("01/01/2006");
document.cookie = "size=" + escape(sz) + "; expires=" + exp;
}

function getData(){
if (document.cookie){
sz = parseInt(unescape(document.cookie.split("=")[1]));
if ( !( cEl = d.getElementById('cz') ) ) cEl = d.getElementsByTagName('cz')[ 0 ];
cEl.style.fontSize = szs[ sz ];
}
else{
startSz = 1;
sz = startSz;
}
}
</script>[/CODE]
Then in your body tag, just put: onLoad="getData()"
Copy linkTweet thisAlerts:
@VladdyMay 25.2004 — Have you tried searching the forum???
Copy linkTweet thisAlerts:
@ahmedthekingauthorMay 31.2004 — good try but it doesnt work!!
×

Success!

Help @ahmedtheking spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...