Client Side JavaScript - Don't use it


JavaScript is supposed to be a standardized language that can be used to make better web pages. There are many examples which prove this to be true.

However, JavaScript suffers from the same problems as Java

NOSCRIPT | Debug | Piracy Prevention
Code Examples - Get Keystrokes | Browser Flavor | Dynamic Menus | Document Date

The NOSCRIPT Tag

According to the HTML 4.0 Reference Specification, the NOSCRIPT block tags should be used to specify HTML content to be rendered if the browser does not render the specified script - JavaScript, VBScript, or what ever. Netscape Communicator 4.05 renders this correctly. However, IE 4.72 does not render the contents.


Debug Problems

Unlike Java, Javascript code is re-loaded when you press F5. It does not matter if the Javascript is included in the html file or is stored is a separate *.js file.


Piracy Prevention

Pirates frequently use frames to decorate their sites with other peoples' pages. You can protect your pages with javascript and Metatag fixes.


Code Examples

The following useful syntax allows a web page to act like a PowerPoint presentation. Just press any key to move to the next page. Unfortunately, while it works in IE 4.72, it does not work in Netscape 4.05.

onkeydown
Responds to all keys, including arrow keys and Ctrl key
onkeypress
Ignores the arrow keys in IE 4.72, same as onkeydown in Netscape 4.05

The location object (or perhaps its window.location?) is not documented in the Microsoft JScript reference

This basically works in both browsers (except that the arrow keys, et al. are different)


document.write ('any string, can include "double quotes" ');


Get Keystrokes

The browsers use different commands to retrieve keystrokes This example code claims to be browser independent.


Determine The Browser Flavor

One of the BIG problems with Java Script is that its implementation is highly browser dependent. Thus, code similar to the following is normally required. Notice that unix and other browser implementations are not considered in this fragment based on code from MSNBC.com.


Dynamic Menus

This site provides the fastest Dynamic HTML / Javascript mouse over pop-up menus I have ever seen. However, there are some minor timing problems.

Here is an explanation and example which works in IE 4.72, IE 5.0, and Netscape Communicator 4.05.


Document Date

JavaScript provides a method to automatically display the date that any document was last changed. However, this code is flakey and browser dependent. Notice the differneces in various browsers for about 8 PM on Monday 01-29-2001. Netscape 4.05 and IE 4.72 were on one machine; Netscape 4.75 and IE 5 were on a second; and Netscape 4.01a was on a third. This Browser is the browser you are currently using, the date indicates when this page was last uploaded to the server. Can anyone say Y2K bug?

Speaking of dates, here is a cool trick. By typing

        javascript:alert(document.lastModified)
into the browser's address bar, you can determine the date that the current page was modified. It takes a little finagling, but this link can also be placed in the IE favorites - after you add a new favorite, right click it, select Properties, and change the URL to the command above. Then simply drag the selection to the top of the menu.

Caution: Some files do not indicate the date they were last modified. As a result, the date reported by document.lastModified is browser dependent. For example

This behavior should be expected for cgi and asp files (their content is generated when the page is requested), but other files may also omit the date modified.

The actual dates sent to Internet Explorer can be checked by viewing

and sorting by Date Last Accessed. (The actual path is OS dependent.) This may also allow you to see when each image (jpeg) was last modified. (For my files, the date reported is when the file was FTP'ed to the server, NOT the date the file was last modified.)


Warning

The following is from Netscape
JavaScript 1.3 contains an ECMA-compliant fix regarding assignments such that if (a=b) is no longer interpreted as if (a==b). You can update the code or, if you want the old behavior, specify <SCRIPT language="JavaScript1.2">.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / HTML_Examples / JavaScript.htm