reptile7's JavaScript blog
Thursday, December 02, 2010
 
Quick Takes
Blog Entry #198

For a while there we were working through the tutorials in HTML Goodies' Beyond HTML : JavaScript sector in reverse order. We had reached "So, You Want A Background JavaScript, Huh?" before jumping up to tackle "A Quick Tutorial on JavaScript Variable Passing"; given below are brief descriptions of the next several tutorials we would encounter if we were to continue in sequence from "So, You Want A Background JavaScript, Huh?".

"Java vs. JavaScript: Similarities and Differences"

Authored by Joe Burns, "Java vs. JavaScript: Similarities and Differences" was one of the very first Beyond HTML : JavaScript tutorials: it appears in the Internet Archive's first (10 February 1999) snapshot of the sector. Per its title, "Java vs. JavaScript" takes a stab at comparing and contrasting Java and JavaScript, a topic you could probably write a small book on; it is a descriptive piece that unfortunately contains no code - Joe could have at least included some sample applet element HTML.

Two other complaints:

(1) The tutorial incorrectly states that both Java and JavaScript use the class data structure to create new objects: true for the former, false for the latter.

(2) If Joe is going to use the word "standalone" to describe a Java application, then he should briefly discuss running Java on the command line, but he doesn't. Relatedly, Joe says, Java applets run independent of the HTML document that is calling for them; this is true in the sense that the browser reads a page's HTML whereas it hands any applets off to a plug-in, but as <object>-type elements go, applets are really not so "independent": unlike embedded images and (iframe) documents, applets cannot be rendered outside of a document context - you can't double-click an applet .class file on the desktop and run it like a C executable, for example.

Mozilla compares JavaScript and Java in the Core JavaScript 1.5 Guide here.

"From DHTML to DOM Scripting [Part 1]" and Part 2

Authored by Christian Heilmann and excerpted from his book Beginning JavaScript with DOM Scripting and Ajax: From Novice to Professional, these articles discuss various JavaScript coding practices, e.g., script externalization, the use of feature detection, authoring with accessibility in mind, and the like. Part 1 moves along at an even pace; Part 2 escalates rapidly in complexity and will overwhelm most newbies. A helpful Summary section is provided at the end of Part 2.

The articles' title posits a false distinction between DHTML and the DOM: when you mutate a document on the fly via a DOM 'setter' operation, you are definitely engaging in DHTML. But don't take my word for it. Consider the append-a-link-to-a-parent-element code that appears in Part 2: the createElement( ), setAttribute( ), appendChild( ), and createTextNode( ) DOM Core methods employed by this code are all listed on Microsoft's DHTML Methods page.

"Browser Detect Script"

Credited to Dan Ragle and imported from WebReference.com, this tutorial presents a colossal, annotated browser-sniffing script - a script that is Exhibit A as to why everybody should code to the W3C's standards, and that's as much as I'm going to say about it.

"Using JavaScript Variables and Built-In Functions [Part 1]" and Part 2
"Writing Your Own JavaScript Functions [Part 1]" and Part 2

Authored by Dave Thau (a.k.a. thau!) and excerpted from his book The Book of JavaScript, 2nd Edition: A Practical Guide to Interactive Web Pages, these are very basic tutorials that really belong in HTML Goodies' JavaScript Primers sector. The "Using JavaScript Variables and Built-In Functions" articles cover variables, arithmetic operators, strings and string concatenation, the document.write( ) method, and the window.alert( ) method (at no point does thau! use the word "method" to classify document.write( ) and window.alert( ), nor does he identify alert( ) as a method of the window object). The "Writing Your Own JavaScript Functions" articles cover the creation of functions, function parameterization, function returns, and the use of local variables in functions.

The "Writing Your Own JavaScript Functions" articles veer into some embarrassingly dated territory. Part 1 works with an openAndCenterWindow( ) function whose body begins with a browser-sniffing conditional meant to flag Netscape 4+*. Even worse, the second page of Part 2 sports a "Dealing with Y2K" section offering code for dealing with the long-obsolete dateObject.getYear( ) method. (And this book was published in 2006.) thau!, if you're out there reading this, you might want to hook up with a better editor if or when you update your book again.

*BTW, upon throwing out the navigator.appVersion and navigator.appName tests, the rest of the openAndCenterWindow( ) code works just fine with MSIE 4.5 in the SheepShaver environment.

"Accessible JavaScripting From The Ground Up"

Authored by Stephen Philbin, this descriptive article is concerned with JavaScript-enhanced Web pages that malfunction for JavaScript-disabled users and how to avoid creating such pages; towards the latter, you are urged to
(a) implement JavaScript as a nonessential extra and
(b) make sure your Web page HTML displays smoothly for one and all before adding any JavaScript to it.

That brings us at last to "How to Populate Fields from New Windows Using JavaScript", which was authored by Jonathan Fenocchi and imported from WebReference.com. Earlier in the sector as part of a tour of the "Opening New Windows With JavaScript" set of tutorials, we checked over "Remote Control JavaScript", which presents a script that uses a secondary window to load new documents into an opener window. "How to Populate Fields from New Windows Using JavaScript" also fits the remote control paradigm, offering code that uses a secondary window to explain and set values for form controls in an opener document.

The "How to Populate Fields from New Windows Using JavaScript" code comprises three parts:
(1) a forms.html opener document;
(2) a style.css style sheet that applies various styles to the forms.html document; and
(3) a help.html remote control document.
A files2 folder containing these documents can be downloaded via the zip file link at the end of the Conclusion section on the tutorial's third page.

The files2 code is a bit of a chore to read through, but it works flawlessly. Links to a forms.html demo and its isolated help.html page are given on the first page of the tutorial; there's no link for the demo's style.css page - view it here. While we're on the subject of links, I should mention that the first page's learn more about opening new windows in JavaScript link to Martin Webb's "The JavaScript Pop-up Window Primer" is dead: the primer can still be read here.

Deconstruction-wise, the author doesn't discuss the forms.html and style.css code at all but provides a reasonably detailed analysis of the help.html code. We ourselves will not go through all of the code line by line but rather will paint a general picture, fill in some blanks, and perhaps suggest some coding alternatives. And as that might take a while, we are probably better off putting it off until the next entry.

reptile7

Comments: Post a Comment

<< Home

Powered by Blogger

Actually, reptile7's JavaScript blog is powered by Café La Llave. ;-)