To Foot
© J R Stockton, ≥ 2013-01-18

JavaScript Index and Introduction

Links within this site :-

This is an incomplete snapshot, from 2012-12-27.

JAVASCRIPT IS NOT JAVA

About This JavaScript Site

This is not a true JScript or JavaScript FAQ (Frequently Asked/Answered Questions list) site (and should not be described as such), since it only deals with what I know something about; but parts of it may serve instead of a Date and Time FAQ for JavaScript / JScript.

I have tried to find optimal or near-optimal approaches for doing things; but, where essentially the same operation is needed more than once, I may have used more than one way. That could be useful if parts of the code are not compatible with all browsers. Repeated function evaluations are not necessarily minimised. Script optimisation may well be capable of improvement; the algorithms should be more useful than the actual code.

Please let me know of any JavaScript browsers in which this code is not correct (indicating the exact nature of the error, and any ideas for its solution). I have to rely for some things on reports from others.

This site was largely written for systems using
ECMAScript 3rd Edition.
ECMAScript 4th Edition does not exist.
ECMAScript 5th Edition is significantly different.
I know virtually nothing of .NET programming.

Servers

Server-dependent aspects will have been tested by me only locally and on the Demon Homepages Web server.

My host does not offer server-side programming. I know virtually nothing of ASP, PHP or CGI, nor of the submission of data.

None of my pages submits anything to a server.

HTML

The HTML is frequently checked with W3's TIDY, using the command line version in a batch file.

Included JavaScript Functions

JavaScript functions of general use within my page set are coded in file inc-cmmn.js, and general date functions in inc-date.js; see Include Files, which describes and shows them. Within a page, such imported functions are often included in boxes with coloured borders.

Without those functions, pages will fail; there is a test at the head of each affected page for the seemingly error-free presence of the necessary include files. Thus, after seeing an alert such as

'File inc-cmmn.js top fault, RSVP!'

one should expect further errors. The include files need to be in the same directory as the page file proper.

Functions specific to a page remain in it.

JavaScript Versions Used

Until 2006-10-14, I used Win98 1st Edn IE 4, on a PII/300.

From 2006-10-19 until 2008-03-19, I used WinXP sp2 IE 6, on a P4/3G.
On 2007-01-18, I got WinXP sp2 IE 7 as well.
On 2007-03-31, I got Firefox 2.0.0.3 as well.
On 2007-04-25, I got Opera 9.20 as well.
On 2008-01-04, I got Safari 3.0.4 as well.
On 2008-09-10, I got Chrome 0.2 as well.
...
From 2009-07-21, MS IE is 8.
From 2012-05-13, Safari is 5.1.7 : final Windows release.
From 2012-12-20, Opera is 12.12.
Seen 2013-01-11, Chrome is 24.0.
From 2013-01-18, Firefox is 18.0.1.

Code may well fail with other browsers, though I hope not.

Since I used IE 4, and RegExps, this site generally expects, both for its own functioning and in its recommendations, JavaScript 1.2 or higher. However, the site no longer supports IE4.

Where a TEXTAREA is used for output, I generally expect a fixed-pitch font. Netscape 6.0 and Safari 3.0.4 did not give this by default; I've now styled it fixed-pitch by CSS.

Much of the code expects that \t in a string will be expanded in output as far as a multiple of 8 characters.

JavaScript Extensions

JScript is Microsoft's version of JavaScript. Extra features can be used in servers using JScript.

For IE-only intranets, and for execution under WSH, JScript coding can be used.

JScript coding cannot be used sensibly on the World-Wide Web, where only that which complies with ECMA-262 3rd Edition is safe.

Copyright

These pages themselves, and their associated files, are copyright, including the Tables and the source code, and so are not to be re-published in whole or in part (but see Site Index); the code of the JavaScript functions and the algorithms may be freely used.

Link Markings

On some pages, links are marked, by JavaScript, with titles. In at least some browsers, the hand-pointer will, when hovering on a link, develop a cuff, marked to indicate whether the link is to the same page, to the same site, to another Web site, or another type. Examples :-

Function Cuffs should be called after the page is loaded.

Anchor Markings

Likewise, anchor names (but not IDs) may be shown on hover.

Function Hooks should be called after the page is loaded.

Code Displayed on This Site

Code in Ridge-Bordered Boxes

An alternative means of code display was introduced on this site in Summer 2010. The actual content of a <script> element is shown verbatim, omitting only its leading and trailing whitespace.

Code in Double-Bordered Boxes

These show the result of applying toString to one or more Objects (commonly functions), with variations.

Introduction

The actual code - not a manual copy, but using <function-name>.toString() - is generally shown in boxes with coloured borders; the code may be in the source of the page, or in an include file :-

This reduces the chance of undetected typos in what is shown. In many cases, test code is displayed within a simple function just to facilitate this.

After using copy'n'paste from such a box, it may be necessary to replace CR (0x0D) with CRLF (0x0D0x0A); any good text editor should have a way of doing this.

Note : MSIE presents the code as written; some other browsers remove comment and change layout, etc.

Examples

This displays a string :-

Boxes like this show the code of one or more functions, and perhaps strings :-

Often, the box is sized to show only the function(s) offered, but test harness can be seen by scrolling the box (indicated by a blank last line, and by a scrollbar thumb).

This shows and executes a function that tests the above function :-

Aside :-


  That is a writeable box, manually executed with eval;
it works in IE4, IE6, IE7, FF2, Op9 & Sf3 at least.

Various Browsers

Functions in these code boxes are displayed by MS IE (all versions, as far as I know) exactly as written, including comments. I write my code (E&OE) to fit within 69-character-wide lines, and my displaying code should choose the height of each box to suit the code to be displayed.

Some browsers add extra blank lines.

Some browsers suppress comments.

Some browsers reformat code (often using more lines).

Therefore, readers should check to see whether they need to use View Source in some form or other.

I have probably improved the situation, with ideas offered by LRN, so that the height of the boxes is calculated for the browser's layout.

The Box-Drawing Code

See Code Boxes, which now contains the descriptions (which previously followed this) of functions such as Depikt() & ShoDoo() which show the boxes.

Other Code

Any code remaining not thus boxed on these pages has been formatted for HTML, and typos may have been introduced since testing. Otherwise, use the links above; or use "View, Source" or "File, Save As", or the equivalent in other browsers. If intending to use my code, take it by preference from the boxes or the source code of the pages. Multiply-used code is in files inc-cmmn.js & inc-date.js, and shown in page Include Files.

Self Test of Pop-Up Function Displaying

The code for this is independent of that for double-bordered boxes.

PopBtn(SafeHTML, PopThis, PopBtn)
PopBtn(PopBtn)

Opera, up to at least version 11.01, gets it wrong.

Include Files

The functions in my Include files are shown, in boxes as above, in Include Files, where include files in general are discussed.

Code Re-use

When code is copied by such as "View Source" then editing down, either a function ShoDoo must be provided or its calls must be replaced; ShoDoo(Fn, n) → Fn() .

Use of CSS

The double-bordered boxes are nominally paragraphs, styled as by CSS but without particular inheritance.

These features use CSS :-

Scripted page text is boxed in this colour
Testing material is boxed in this colour
Other source code is boxed in this colour
Other material is boxed like this, but may use a different colour

If colourings given by CSS are not rendered acceptably on your system, try saving the page to a local file on your machine and looking at the local file; the CSS file(s) will then not be found. But, for the JavaScript to work, you will need to have the relevant include files saved in the same directory.

If you want local copies to retain the style, put a copy of the cached CSS file(s) in the same directory.

About JavaScript

JavaScript is mainly used to give facilities for safe calculation (in the widest sense) to Web pages. Less commonly, VBScript (needing MS IE) is used for that. PerlScript is apparently possible, by using a plug-in.

Ideally, JavaScript would behave identically in all browsers. In practice, that is not always the case.

JavaScript can also be used in Batch Files and WSH Scripts and there runs under Windows Script Host, with greater access to the local system; but for this purpose VBScript is more common, and Perl is often used in Batch.

JavaScript can also apparently be used in Acrobat with PDF.

JavaScript and Java are different languages; and "Java script" is not a valid term.

JavaScript is a case-dependent language : true and TRUE are entirely different.

For JavaScript questions in general, see in newsgroups such as news:comp.lang.javascript and in the FAQ of news:c.l.j.

Standards

JavaScript is defined by International Standard ISO/IEC 16262. That is similar to Standard ECMA-262 3rd Edition, and virtually equivalent to Standard ECMA-262 Edition 3 Final. The term ECMA-262 is commonly used to refer indiscriminately to the standards. All are freely available in PDF format - see via External Links below.

The 5th edition of ECMA-262 was released in December 2009.

JavaScript in Web Pages

Example

... HTML ...

<script type="text/javascript"> // NOT language="..."

	function Fn() { document.write("Output of Fn") }

	ShoDuu(Fn) // ShoDuu is already declared, to show and execute Fn

</script>

... HTML ...

Writing to a Page

Note that, while a page is loading, document.write and document.writeln can be used to write to the current page; but that, after loading, any use of either will open a new page.

To write to a loaded page, assign to the value of a control, or use old function DynWrite or get the ID of an element and assign to its innerHTML as in function

Note that changes may only actually be shown (except maybe for the status line or for controls; browser-dependent) after code execution pauses or stops. To give the illusion of writing while processing, use setTimeout(..., 10) at the close of a section of execution to start the next section.

JavaScript in Batch Files and WSH Scripts

In Win32 systems at least, JavaScript can be used to enhance DOS batch files - see in my MS-DOS Batch Files for more. Example :-

@echo off
echo.> ~$.js
echo "function LZ(x) {return(x<0||x>9?'':'0')+x}" >> ~$.js
echo  with (D = new Date()) { >> ~$.js
echo    WScript.Echo( // 'GMT ' + >> ~$.js
echo      getUTCFullYear() + '-' + LZ(getUTCMonth()+1) + '-' + >> ~$.js
echo      LZ(getUTCDate()) + 'T' + LZ(getUTCHours())   + ':' + >> ~$.js
echo      LZ(getUTCMinutes()) + ':' + LZ(getUTCSeconds()))  >> ~$.js
echo    } >> ~$.js
type ~$.js | SUBS 34=32 > ~$.js
:: type ~$.js
cscript //nologo ~$.js | STOW GMT
:: as 2003-12-24T14:20:18
del ~$.js

That shows, in my Win98 1st Edn, that the GMT/UTC date/time in ISO 8601 form can be saved, by interpreted script from a batch file, in a DOS box. The output of the cscript command can be redirected or piped, as here by my STOW which stores it in the environment variable GMT.

Note the use of my SUBS to remove '"', those quotes are used to allow '<' & '>' in DOS echo . It will often be better to create the *.js file independently.

I intend to look into this further.

The following indicates how a localised addition can make code for one system testable in another :-

S = 'GJC'
document.write = alert  // try removing this line
WScript = {Echo:document.writeln}
WScript.Echo("S = " + S)

Script Maintenance Tools

MiniTrue is very useful (for those who can use a UNIX, Windows or Dos command line) for searching or systematically editing a site.

I have coded ways, using a DOS view of a Web site, of checking the matching of relative links and anchors (CHEKLINX.EXE) and of rapidly creating a list of relative links to existing anchors (FINDANKA.BAT). For a little more description, see On Reading Web Pages; for the files themselves, see directory programs/, and its expanded equivalents 00index.txt and 00index.htm.

My page Check Local Links and Anchors also checks the matching of relative links and anchors, and other things. Use a copy on your local system.

JavaScript Newsgroups

Valid properly-formed Usenet newsgroups relevant for JavaScript include :-

"Group" news:comp.lang.java.javascript is at best of dubious validity, and therefore has limited propagation. Avoid it.

The usual Usenet rules of etiquette ("netiquette") apply; author compliance renders communication more effective, and thus useful responses more likely. Before posting, read the FAQ of news:comp.lang.javascript.

On the use of plaintext and of quoting, see http://www.usenet.org.uk/ukpost.html; it is written for news:uk.*, which has the same conventions.

Text lines should not exceed about 72 characters. Code lines must not be machine-wrapped. Code should be lightly indented to show its structure; do not indent with Tabs.

See Timo Salmi's Usenet Q&A, and my Usage of News. See also other links in this section.

For newsgroups in general, see my Mainly About News-Groups.

Remember that the Net is an international medium; where the matter in question may be affected by locality, always make the locality or localities clear. The world is not yet homogeneous.

In very brief :- No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

Notiquette

Usenet etiquette is governed by the RFC and FYI documents. There is no place in it for other "rules" imported from non-Usenet hierarchies :-

Ignore all claims otherwise.

Such usages as "borken", "MS Exploder", etc., are juvenile; moreover, they inhibit text searching.

Access to News

Usenet News is a public, collective, self-organised, free medium, which does not belong to any particular provider*. It should be accessed by standards-compliant newsreader software (which MS OE approximates to). On the Web, it can also be accessed in a more-or-less acceptable manner via Google Groups (but see in About News-Posting).

Beware of other Web-based "services", which may render articles improperly, impose censorship, suppress or mutilate articles, or otherwise misbehave.

* : Some specific hierarchies, such as news:microsoft.*, have been intentionally distributed by the standard News mechanism; others, such as news:borland.*, are intended to be single-hosted; check for local rules.

External Links

Java is not JavaScript; but for information on Java, CSS, HTML, and browsers, try Roedy Green's site (best by Broadband).

When searching the Web for "JavaScript", you may want also to search for the Microsoft name, "JScript".

Script Standards

These are the prime authorities :

References

General Web links

Web FAQs, etc

Script FAQs

JavaScript Links

These are not all fully evaluated; multi-source collections can be "Curate's Egg" :-

JavaScript Books

Always check for imminent new editions :-

I have copies as marked by †. I find the Pocket Flanagan very convenient, because of its size.

Home Page
Mail: no HTML
© Dr J R Stockton, near London, UK.
All Rights Reserved.
These pages are tested mainly with Firefox and W3's Tidy.
This site, http://www.merlyn.demon.co.uk/, is maintained by me.
Head.