Java Script Lesson 2 - Learning About Objects
JavaScript ’ Lesson 2 ’ Learning About Objects
Now that you have a good foundation in JavaScript, you are ready to start learning more about how it works and the different objects you can use in your scripts.
The most commonly used object is document.write. Document refers to the object, and write refers to the method of the object. This object is used when you want your script to display text.
The document object has several properties, as well as methods.
Properties:
bgcolor ’ This is the background color
fgcolor ’ changes the foreground or text color
referrer ’ will provide the url that your visitor was on before clicking to your site
lastModified – will provide the date that the page was modified
Methods:
Write ’ as shown above, this is used to write something
WriteIn ’ this is similar to the above method, except that it writes a new line.
When you call an object in your script, you will first name the object, then follow this with a dot (.) and then add in either the property or the method. For example:

The result of this script would be: We last updated this page on: December 1, 2000. The script figures out the last time the page was modified and returns the result where you have called for sample in the above script.
You could modify the above script by adding the properties mentioned above, or by changing the words to suit your page.
If you wanted to show the link that your visitor just left before coming to you site, you could enter in the following script:

This script would then display:
Thank you for clicking the link at: http://www.lastsitevisited.com
Now, these are just simple examples of what objects in JavaScript can do for your site. As we have stated previously, syntax is very important when you are writing JavaScript. If you were to write the above script as:
WriteIn.document (document.referrer)
Instead of document.writeIn, the script would not function properly. You must always put the object first, followed by either the property or method.
Our next lesson will cover JavaScript arrays and how you can implement them into your site. Arrays are very useful for creating ordered lists, and improving the layout of your information.
Related Posts:Posted on 12/27/05 1:45 AM
Be the first to comment!