<script language="JavaScript"> <!-- JavaScript Instruction; // --> </script> |
JavaScript Code Marks the beginning and end of JavaScript code. Use of the HTML comment tags within ensures that a browser that does not support JavaScript (or perhaps where someone has disabled it in their browser preferences) will ignore all of the code. Each line in the code ends with a semi-colin ; JavaScript can reside either in the <body>...</body> or the <head>...</head> of an HTML document. |
Lesson 27 |
// single line comment <!-- single line comment /* multi line line comment */ |
Comments Provides a way to provide descrptive annotations in JavaScript code. These lines are not interpreted as instructions when the page loads. |
Lesson 27 |
alert('String of text'); |
Alert Message Displays the text string in an "alert box". |
Lesson 27 |
<a href= .... onClick="doSomething">...</a> <a href= .... onClick="doSomething; return false>...</a> <img src=... onClick="doSomething"> |
onClick event Responds to click of the mouse on a hypertext link or an image to issue a JavaScript command. Adding the command return false instructs the web browser to ignore the link reference in the href= part of the tag. |
Lesson 27a |
<a href=... onMouseOver= "window.status='text of custom message'; return true"> |
mouseOver Link When the mouse is moved over a hypertext link, the message in the quotes is displayed in the browser status bar, rather than the URL of the link. |
Lesson 27a |
document.write('...'); |
Write Content Writes the content to the page as it loads. The content can be dyanmic data (i.e. the date, results of a culation, information about the document or the web browser) |
Lesson 27b |
document.lastModified document.location.href document.title |
Document Information Properties of the document (i.e. the HTML file); lastModified is the time and date it was last changed; location.href is the URL of the HTML file; title is whatever text is inside the <title>...</title> tags. |
Lesson 27b |
if (some condition) { doThis; } if (some condition) { doThis; } else { doThat; } |
Conditional Branching Issue a command only if some condition is tested and evaluated to be true (IF-THEN). The second example allows you to do one thing if the condition is true and something elese if it is false. |
Lesson 27b |
t = new Date(); t.toLocaleString() t.getDay() |
Date Object The new Date() commands creates a data object that holds the date and time (according to the computer in use). Once declared into a variable, we can get different parts of this data- getDay() returns the day of the week (0=Sunday, 1=Monday...). JavaScript provides other functions to get the month, day of the month, year, etc. Uisng the property X.toLocaleString() will return a date and time that is appopriate for the settings on the local computer (since different countries have different convetions for diaplying the date). |
Lesson 27b |
navigator.appName navigator.appVersion |
Navigator (Browser) Information The naviagtor object contains information about the web browser software; appName tells us which browser is in use (NetScape, Internet Explorer, etc); appVersion tells us what version. |
Lesson 27b |
window.open( 'URL', 'window_name', 'window_options') |
Open A Window When called, this will create a new browser window, placing in it the contents specified by URL. The value of window_name can be used later to send or get information from this window. The window_options include the features of the new window toolbar displays the browser buttons (forward, back, home, print, etc); location displays the field that shows the URL for the window; directories displays other web browser directory buttons; status displays the browser status bar at the bottom; menubar displays the web browser menu bar; resizable allows user to change the size of the window; scrollbars provides scroll bars if the content is larger than the window size; width=XX height=YY specifies the height of the window when opened, in pixels; screenX=hh,screenY=yy specifies the location of the upper left corner of the window, measured from the top left corner of the monitor (for NetScape 4.0 only); left=hh,top=yy specifies the location of the upper left corner of the window, measured from the top left corner of the monitor (for Internet Explorer 4.0 only) |
Lesson 29c |
self.close() |
Window closes itself A command to close the active browser window. |
Lesson 29a |
Writing HTML Summary of HTML Tags: JavaScript
©1994-1999
Maricopa Center for Learning and Instruction (MCLI)
Maricopa Community Colleges
The 'net connection at MCLI is
Alan Levine
Comments to alan.levine@domail.maricopa.edu
URL: http://www.mcli.dist.maricopa.edu/tut/tags/tag7.html