tags:

views:

77

answers:

1

Hello,

I use the below script to allow visitors to my page to increase / decrease the font size (or restore the font size to its default setting).

Does anybody know how I could get each page to retain the increased/decreased font size of the previous page? Currently, when a visitor adjusts the font size and goes to another page the font size returns to the default size, meaning that the visitor then has to re-adjust the font size again for each page they visit. It would be nice if once the visitor adjusts the page size on one page and then goes to another page, that other pager would automatically appear in the adjusted font size. Thank you, Chris

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;  
}

And the HTML:

INCREASE: <href="#" onclick="changeFontSize('mydiv', true); return false;">  
DECREASE: href="#" onclick="changeFontSize('mydiv'); return false;">  
RESET TO DEFAULT: <href="#" onclick="resetDefaultSize('mydiv'); return false;">
+1  A: 

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 your 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.

Tim S. Van Haren
http://www.quirksmode.org/js/cookies.html
Dave Jarvis
Hello Mr. Tsvanharen. I would like to hire you to write a cookie/javascript that would do the above. Please let me know if you would be interested. Thank you, Chris
Chris