ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
Giving Them Enough Rope....
HTML TUTOR --- 09/17/2002

Paul V. Miller

HI everyone! Thanks for tuning in to this week's edition of the HTML Newsletter. This time around, I'm going to show you how to let visitors to your Web site have a little more control over their surroundings -- the look of your page, to be specific. This week we'll talk about enabling users of your site to change the background and text colors on your page. We'll use a little JavaScript for this one, but it's nothing you can't handle.

To begin with, what I'm about to show you is probably not the greatest thing to throw into your page without first considering what kind of page you have in the first place. It's up to you to decide what your visitors are going to appreciate. In some cases, allowing users to choose a background color isn't going to add much to your site overall.

This trick works best on pages with little text -- mostly because readability of text relies so heavily on contrast. Most of the time, when you have a lot of text to present, it's better to just choose a light color for the background, a dark one for the text (or vice-versa), and leave it at that. However, when you let people choose their own colors, you take the chance that they're going to choose colors that make it harder to read your site. This could be bad. On the other hand, depending on your site's content, this might be just the thing to liven up your page. A children's site, for instance, with few words, might be a perfect opportunity to try this out. Either way, getting the code into your page is the easy part.

Another nice thing about this trick is that you get to choose the colors that your visitors will have to pick from. This means you can make sure they wont have the opportunity to give your page a black background with orange text... unless you want them to.

The part of the code that's most useful to us is the following:

document.bgColor = '#006600';

In this case, #006600 is the color we want to choose for the background of the page. So, we'll put this line of JavaScript code inside a link, to let people choose it, or another color:

<a href="#" onclick="document.bgColor = '#006600';">green</a> <a href="#" onclick="document.bgColor = '#003399';">blue</a> <a href="#" onclick="document.bgColor = '#CC0066';">pink</a>

And just like that, you've enabled your visitors to make a rather drastic change to your page. You should use the Hex Codes for whatever colors you want to make available-- check out the HTML archives for my series on Web safe colors to get more information on that.

I also promised that I'd tell you how to let your guests change the text color as well. It's as easy as this--simply replace the "bgColor" in the code with "fgColor" and you'll give them control over the color of your words as well as of your background. Note: the fgColor doesn't always work in Netscape 4. You may want to test this out in your browser before uploading to the Web.

Not to tough, right? Try it out for yourself and see how it works. That's it for this week. Hope you had fun. Take care of yourselves and see you next time!

 

Paul V. Miller designed his first Web site in 1996 and has been a freelance designer ever since. Paul currently teaches HTML and JavaScript, as well as doing freelance Web design for non-profit organisations in New York City. He still types out all of his HTML by hand, even though his friends with GoLive think he's nuts. Paul is based in Brooklyn, NY and can be reached at Paul.Miller@itworld.com.



 Home   Newsletters  HTML TUTOR
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   Industry Standard   Infoworld   ITworld  
JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

DEMO   IDG Connect   IDG Knowledge Hub   IDG TechNetwork   IDG World Expo  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.