SHARE
Facebook X Pinterest WhatsApp

HTML Goodies: Script Tip: Week 68

Written By
thumbnail
Joe Burns
Joe Burns
Jan 4, 2005

 

Howdy…

     This week, it’s a re-do of the color script so that it will run in Netscape Navigator. It took a few
major changes, but it’s nothing we can’t roll through in one tip.



Here’s the Effect

Here’s the Code

It’s long, get it all.


     Alright, let’s just stop and think it through. In order for this script to run in
Netscape Navigator(NN), you must eliminate all of the commands that NN doesn’t understand. So the document.all and document.all(“box”).style.background goes away.

     You have to flip the script upside down for NN to run it. You see, in order for
NN to run hierarchy statements, the elements must already be loaded into the browser memory. In the case of the MSIE-only script, the commands came first and then the table was built. It’s opposite here. First you have to build the table, then you can post the function.

     Finally, in NN, table cells are not seen as individual items. You cannot change a specific cell
in a dynamic fashion. You can, however, change the page background. We’ll do that.

Lose the MSIE-Only Commands

     The biggest thing is to find an equal to the way the original author worked with document.all. It was basically a line of code that had to be true for the function to work. So I set up an If statement that would always be true. The code is right at the top of the script.


var zork = 1
if (zork==1)

     I created a variable named “zork” and set it to 1. Next I asked if “zork” was equal to 1. It is, of course, and the script goes on. The drop down menu is assigned the entire run of hex codes.

Flip the Table and Function

     Note the script. I just copied and pasted the document.write statements up above the function. It was a simple cut and paste.

Change the Page Background

     Step three is to set up the script so that it’s the background that’s being changed rather than the table cell. The first line of code in the function is now set up to alter document.bgColor. That’s the background of the page. The user’s choices are gathered just the same way as before. I didn’t change that at all.

One More Slight Change

     Instead of having the page background come up white, I had it come up black since that’s what the drop down menus read when the page is first loaded. I did that by adding a BGCOLOR attribute in the BODY flag.

     Now the script will run in Netscape as well as MSIE. This is actually a good way to help yourself learn JavaScript. Find a script that will only run in one browser or another. Then take the time to find out why and alter the script so it will run in both.

     Because of the make-up of the browsers I wasn’t able to get the effect exact, but I got pretty close, don’t you think?

Next Week: Dynamic Headlines



     Do YOU have a Script Tip you’d like to share? How about suggesting a Script Tip to write about? I’d love to hear it. Write me at:
jburns@htmlgoodies.com.

Learn to write your own JavaScripts with the

Recommended for you...

The Revolutionary ES6 Rest and Spread Operators
Rob Gravelle
Aug 23, 2022
Ahead of Time (AOT) Compilation in Angular
Tariq Siddiqui
Aug 16, 2022
Converting a JavaScript Object to a String
Rob Gravelle
Aug 14, 2022
Understanding Primitive Type Coercion in JavaScript
Rob Gravelle
Jul 28, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.