In this article, you'll learn that it requires only a few lines of Java Script to let the visitors to your Web site control the font size. You'll also learn how to use a cookie to store their preference on their computer.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

Easy Java Script Code to Let Your Web site Visitors Set Font Size

Why should you let visitors to your Web site set the font size? According to the U.S. Census Bureau, adults 50 plus will grow to over 106 million by 2015, when they will account for 45 percent of the adult population. Not only is the population aging, but adults 50 plus are also the fastest growing segment on the Internet. If your Web site is directed toward seniors, or people with visual impairment, giving your Visitors a way to set the font size is crucial.

In this article, you'll learn that it requires only a few lines of Java Script to let the visitors to your Web site control the font size. You'll also learn how to use a cookie to store their preference on their computer. You'll also learn how to set the cookie so that their one time font size preference will apply to every page on your website, and when they leave your Web site, they won't have to set it again when they return.

• Before you proceed, consider what impact changing the font size may have on your webpage layout. In some cases, this may cause your layout to stretch and distort. You may need to go back and set absolute dimensions for some elements.

The first step is to add the attributes shown below to the <body> tag of your webpage.

<body id="myBody" onLoad="setFont();">

The first attribute assigns an id to the body element. This will also work with other webpage elements like a div, span, or table. The second attribute makes the onLoad event of the body tag execute a function named setFont. This function will be used to set the initial font size every time a webpage loads. The code for the setFont function is shown below. Paste this Java Script code block into the <head> section of your webpage.

<script type="text/javascript">

var sizeFont = "=12px";

function setFont()
{
var setSize = sizeFont;
document.getElementById("myBody").style.fontSize = 
   setSize.substring( setSize.indexOf("=") + 1, setSize.indexOf("x") + 1  );
}

</script>

This code creates a global variable named sizeFont and initializes it to the string value "=12px". The setFont function creates a variable named setSize and initializes it with the value in sizeFont. It then uses the String object's substring method to extract the substring "12px" from setSize, and uses the document's getElementById method to set the size of the font.

The second step is to place the two links shown below at the top of the <body> section of your webpage.

<a href="javascript:changeFontSize(1)">Bigger Font</a>
<a href="javascript:changeFontSize(-1)">Smaller Font</a>

• You could get fancy and make these links into styled buttons or graphic image buttons.

Content is Currency

RSS Feed RSS Feed



Web Design Sections

Eloquent JavaScript: A Modern Introduction to Programming

Eloquent JavaScript

Eloquent JavaScript Eloquent JavaScript goes beyond the cut-and-paste scripts of the recipe books and teaches you to write code that's elegant and effective. You'll start with the basics of programming, and learn to use variables, control structures, functions, and data structures. Then you'll dive into the real JavaScript artistry: higher-order functions, closures, and object-oriented programming.

Reader Anthony says, "This book is not your typical Javascript book. Others have a utilitarian approach. In stark contrast, Eloquent JavaScript does not merely provide you a checklist of things to learn but rather paints a panorama of the possibilities that programming provides. Javascript is merely the tool used to introduce these to the reader.

Click here for more information.


Best Laptop Deals at TigerDirect
[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268