So, the easiest to implement method is definitely to use JavaScript to alter the font size dynamically (and set a cookie to remember the user’s font size). I’ll assume you’re using jQuery, because, well, you should be 😉
Firstly, we’ll define a function to resize the text and set it into a cookie. We’ll also include some functions to let us use cookies easier.
$(document).ready(function(){
/**
* Cookie utilities
*/
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 = ""; } [removed] = name+"="+value+expires+"; path=/";}
function readCookie(name) {var nameEQ = name + "=";var ca = [removed].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);}
/**
* Resize the text
*/
function resize_text(multiplier) {
if (document.body.style.fontSize == "") {
document.body.style.fontSize = "1.0em";
}
if (readCookie('font_size')) { document.body.style.fontSize = readCookie('font_size'); }
document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";
createCookie('font_size', document.body.style.fontSize);
}
});
We’ll then attach this function to the click events of our links.
$(document).ready(function(){
$('#font_size_increase').click(function(){ resize_text(1); });
$('#font_size_decrease').click(function(){ resize_text(-1); });
});
Make sure you add two anchors to your page with the IDs of font_size_increase and font_size_decrease respectively. When the users click on these links, the size of your site’s font should resize dynamically! Refresh the page and it should maintain the page size.
References - The cookies scripts, Text resizing