/    Sign up×
Community /Pin to ProfileBookmark

Can’t find javascript / cookie!

Hi Everybody!! CowGirl is here!!

I was able to come up with a script that lets visitors to my website click on a button and increase/decrease/reset the font size. The only problem is that when they go to another page of my website, the font size reverts to the default setting, meaning that they visitor must again manually increase/decrease the font size. Clearly, this is inconvenient to the visitor. Thus, I would like each page to retain the increased/decreased font size of the previous page. I understand that the best way to do this is to use a cookie to save the user’s selected font size when the font is changed by the user (increased, decreased, reset). Then every time a page on my site loads, check if the user has that cookie. If so, retrieve the cookie’s value and set the font size to the font in the cookie.

Problem is I am not an expert in cookies. I was using the increase/decrease/reset font size javascript function of [URL=”http://www.discoveryeye.org/”]http://www.discoveryeye.org/[/URL] as an example I could learn from. But, I cannot seem to find the cookie (which I assume is part of the javascript function) that [URL=”http://www.discoveryeye.org/”]http://www.discoveryeye.org/[/URL] uses to remember the font size of the page previously viewed. I was wondering if anybody can find the page at [URL=”http://www.discoveryeye.org/”]http://www.discoveryeye.org/[/URL] where this cookie is?

My website is not done, but I published a few pages with the adjust font size javascript at [URL=”http://www.14kt.eu/”]http://www.14kt.eu/[/URL]. In case you are wondering, the script and html used in my website is below.

SCRIPT (BEGIN)
function changeFontSize(objId, doIncreaseSize) {

var currentSize = 0, obj = document.getElementById(objId), newVal = 0, limitMax = 1.7, limitMin = 0.9, unit = 0.1;

if(!obj){

return false;

}

currentSize = parseFloat( obj.style.fontSize );

if (!obj.originalSize) { obj.originalSize = currentSize; }

if(doIncreaseSize){

unit = -unit;

}

newVal = currentSize – unit;

if(limitMax >= newVal && limitMin <= newVal){

obj.style.fontSize = newVal + “em”;

}

return true;

}

function resetDefaultSize(objId) {

var obj = document.getElementById(objId);

if(!obj){

return false;

}

if (obj.originalSize) { obj.style.fontSize = obj.originalSize + “em”; }

return true;

}
SCRIPT (END)

HTML (BEGIN)
INCREASE: <href=”#” onclick=”changeFontSize(‘mydiv’, true); return false;”>

DECREASE: href=”#” onclick=”changeFontSize(‘mydiv’); return false;”>

RESET TO DEFAULT: <href=”#” onclick=”resetDefaultSize(‘mydiv’); return false;”>
HTML (END)

Thank you for your time, CowGirl!!!!!!!!!!!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @CowGirl 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...