|
Help
CodingForums Partners
This is a
![]() |
|
Document Object
|
The column on the left are properties of the document object. They are static attributes of the object. Lets say you want to write out the date and time of the last modification to your page onto the screen. Here's what you would do:
<script type="text/javascript">
var example
example=document.lastModified
document.write("This page was last modified: "+example)
</script>
Output:
Whenever you update your page and save it, this script will display the date and time of this occurrence. Something you can add to the end of your page right now! In this example, "document.lastModified" is a property of "document" Its a static attribute of the current document. In order to show this property, we used the non-static method to write this information out. Notice that we used "+" to put together "This page was last modified:" and example. The "+" sign is used to "combine" strings into one-similar to math, in a sense.
As you can see, as long as you know the object name and what methods and properties it contains, you know how to use it! The majority of commands in JavaScript are referenced by first specifying the object name, than a dot (.), plus the method/property.
Lets try playing around with another document method then. Looking at the above chart, lets use "referrer", which gives the URL of the page that you came from to get here. Lets see what this might be useful for:
<script>
document.writeln("Please thank this site for adding a link to me!")
document.write(document.referrer)
</script>
Ok, maybe not so useful like this, but you get the point.
As you learn more about JavaScript, you will bump into more objects. All objects' properties and methods are accessed in the same manner as above- first by specifying the object name, then a dot (.), then the method or property you want to use from it.
Remember, JavaScript is a language of objects- 95% of what you'll want to do with JavaScript will involve simply picking the right object and using it!