Object Properties
I am getting the gist of the hierarchy of JavaScript, but Chapter 3 goes more indepth on this. At this time, I know document is an object, and write is a method. I know that methods do something to objects. I understand how to write the object-and-method format in JavaScript. There is a another aspect of the JavaScript hierarchy: object properties, which is like a subsection of an object. Properties hold specific characteristics about the object. For example, properties of a document can be background color, text color and location. Besides the document object, we have other objects:
- navigator: represents the browser
- history: represents the list the browser keeps of all the pages the user visited during the current online session
- location: represents the current URL of the page being displayed
In the HTML box below, the scripts cover these four objects and many of their properties:
HTML file: |
Displayed by browser: |
<BODY>
<!--Writing document Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("The background color of this page is <B>" +document.bgColor+ "</B>.")
document.write("<BR>The foreground (or text) color of this page is <B>" +document.fgColor+ "</B>.")
document.write("<BR>The link color of this page is <B>" +document.linkColor+ "</B>.")
document.write("<BR>The active link color of this page is <B>" +document.alinkColor+ "</B>.")
document.write("<BR>The visited link color of this page is <B>" +document.vlinkColor+ "</B>.")
document.write("<BR>The URL of this page is <B>" +document.location+ "</B>.")
document.write("<BR>The page you were at before this page was <B>" +document.referrer+ "</B>.")
document.write("<BR>Here's what's written in the TITLE of this page: <B>" +document.title+ "</B>.")
document.write("<BR>The document was last modified: <B>" +document.lastModified+ "</B>.")
</SCRIPT>
<!--Writing navigator Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("You are using <B>" +navigator.appName+ ".</B><BR>")
document.write("It is version " +navigator.appVersion+ ".<BR>")
document.write("Its code name is " +navigator.appCodeName+ ".<BR>")
document.write("It sends the header " +navigator.userAgent+ "." );
</SCRIPT>
<!--Writing history Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("You have visited " +history.length+ " pages before this one.")
</SCRIPT>
<!--Writing location Object Properties-->
<SCRIPT LANGUAGE="javascript">
document.write("The name of this location is <B>" + location.host + "</B>." )
</SCRIPT>
<SCRIPT LANGUAGE="javascript">
document.write("The name of this location is <B>" + location.hostname + "</B>." )
</SCRIPT>
</BODY>
|
|