Different font sizes on website

My website has a menu named Font Size. Basically its an option for user to change font size of website like:

smaller
small
medium
large

Default font size is "small". When user selects font size say "medium", then font size should remain medium throughout user's visit to all pages of that website(in one browser session). How to achieve this through JavaScript or jQuery or anything else.

I tried changing font size on selection but when I go to another page font size changes to default font size.

My website already using HTML5, CSS3, JavaScript, Jquery. Its on Spring MVC/Java.

Answers


In an ideal world, you would have all over the elements on your page based on a percentage of the body font size, e.g.

body{ font-size: 12px; }
h1{ font-size: 120%; }

or

h1{ font-size: 1.5em; }

If you had this set up, then you can simply change the font-size of your body element, and this will then automagically update all the fonts on the page.

As Baadshah has suggested, you can use the jQuery cookie plugin to persist your users selection across all pages.

I have put together a simple demo here at jsfiddle

You can change the body font-size based on the selection, set the cookie, and then check to see if this cookie exists, then set the font size.

if ( $.cookie('font-size') ){
    console.log($.cookie('font-size')); // take this out when not debugging
    $('body').css({ 'font-size': $.cookie('font-size')});
}

use cookies

 var cookieFont = $.cookie("fontSize");
  $("#target").css("font-size", curFont + 'px');

DEMO


Need Your Help

PowerShell “echo on”

powershell command echo

This is a duplicate of http://serverfault.com/questions/102098/powershell-script-showing-commands-run. I thought it would be more appropriate to ask this question here.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.