![]() |
JR's HomePage |
Updates |
Site Map | Page Bottom Why Use JavaScript | Cautions | Programming Notes Conventions, Tools and Samples |
JavaScript Authoring Info
JavaScript is an easy way to make a website visually attractive to clients and other viewers by adding interactivity and dynamics to HTML pages. This page explains why one would use JavaScript in their website designs. It also has links to JavaScript tools, readings and samples for those who prefer ready-to-run effects. And finally for those who prefer to roll their own there are my programming notes, introductory tutorials, small projects, larger projects and form projects pages.
Why Use JavaScript
Why should a webpage author use JavaScript in addition to HTML?
|
Javascript adds user interactivity Javascript enhances visual displays JavaScript allows many page effects |
Javascript allows client-side user form validation Javascript provides seamless integration with user plug-ins Javascript allows access to some system information |
Here are just a few of the many effects that can be added to your webpage:
Here are some examples of useful applications:
|
Cautionary Notes
As with any software there are flaws that are only discovered after release and are resolved as they are reported. Just be aware that careful design and thorough testing are needed to make sure your project works for others as well!
Language Design Issues
Because JavaScript uses a high-end approach to security (leaving lapses in the domain of the browser) there are some applications that it is not appropriate for:
- JavaScript does not have user file access. You must use cut/paste techniques to input or save data.
- JavaScript cannot run programs on the host machine unless it is through browser plug-ins or associations allowed within the browser.
- JavaScript has no access to the user environment other than what the browser provides. Hence no access to the Windows registry is possible.
- JavaScript is definitely not a system programming language! Use Java or C++ for this type of activity.
Language Implementation Issues
Although JavaScript is easy to understand and to write, there are several reasons rigorous testing is required.
- The recommended interface with html documents [DOM] has changed and many older JavaScript applications are now obsolete. Read this as NOT ALL PUBLISHED SCRIPTS WORK ON MODERN BROWSERS!
- Programs that block popup screens can interfere with your assumptions of what a viewer sees.
- There are browsers (mostly text-only and vocalizing) that have no JavaScript support whatsoever.
- Some users choose to turn JavaScript support OFF.
WARNING: Programmers must Test! Test! Test! every JavaScript on several browsers to make sure expectations are met.
Programming Notes
JavaScript is a scripted language which is object oriented, event-driven, and platform independent. Each of these modern concepts in programming methodology are easier to work with in 'new' languages rather than being bolted on to older ones. And the syntax is similar to that of C and Java. This makes JavaScript a 'good' choice for learning as a first programming language.
What other reasons are there for learning to program in JavaScript:
- No proprietary development system is required. A simple editor is all that is needed to write Javascript code. Any browser will run JavaScript.
- Version control is simple as there is only one active version -- the one on your website.
- Some functions that you want to accomplish have not been written yet.
- JavaScript code is open source and freely available.
- Sometimes you want to customize a canned program to make it unique.
- Many canned scripts are browser-centric (notably MSIE) or out of date
I have prepared a series of introductory tutorials on JavaScript programming. The first few have some short demos that do interesting things. Those who only cut and paste code may also find something useful while cruising through these tutorials. Give it a try!
Conventions, Tools and Samples
Javascript code should always be written to the ECMA-262 - 5th Edition standard. Writing code to standard conventions helps avoid many common programming issues. One of the best ways to check your work is to use jsLint. Just cut and paste your script into the input box and press the jsLint button. Either you will get an 'ok' message or an easy to interpret message including a line number for any problem. Code that checks out ok with jsLint will be less likely to be quirky in any of the modern browsers.
Every programmer builds his own personal toolbox of utilities. For JavaScript this toolbox must include current versions of the mainline browsers: FireFox, Opera, Safari and MSIE. Amaya is also a handy tool to have as it spots HTML code validation problems which hide JavaScript bugs. The editor of choice is TextPad which can be customized with macros for fast programming as well as viewing each browser's rendering without leaving the editor. Some useful tools are:
- DoJo Toolkit provides charts, enhanced UIs and APIs
- FormFaces implements Xforms syntax for use in any browser.
- JQuery provides a library of commonly used effects and tools.
Why create code if someone else already has done it? The following sites may already have the functions you want and probably many more that you didn't even think about. Spend some quality time trolling for ideas.
CAUTION #1: Most scripts offered by these sites are not conformant code. Be prepared to spend some time with a validator. Common mistakes are the use of language="JavaScript" instead of type="text/javascript" and not escaping the forward slash with a backslash (eg. </p> instead of <\/p>) within HTML closure tags.
CAUTION #2: Some examples work with only one or two browsers. Spend some time testing with a variety of browsers including all major engines (ie. Firefox. Opera, Safari and MSIE/SlimBrowser).
CAUTION #3: JavaScripts that bring up new windows are not compatible with Ad Busting software. Take some time to test your scripts in various environments.
CAUTION #4: JavaScripts that bring up new windows are not always compatible with frameset based pages. This may explain why a published script may not be working for you.
