FAQ update (roundup of pending requests - for comment)

Richard Cornford

Usenet Archive
Joined
Aug 17, 2002
Messages
6,000
Reaction score
0
You may have noticed Jim saying that he is too busy to do an update of the FAQ at the moment and asking for volunteers to edit the next (and possibly future) revision. He had already asked me if I was interested and I did volunteer, pointing out that because I am a dyslexic with a tendency to be long-winded[1] I might not be the best candidate for the job of FAQ editor. However, Jim asked me to do it, which probably means that nobody else volunteered at all.

I have successfully established access to Jim's server and am ready to start the next revision of the FAQ. To that end I have searched the c.l.j. archives for <FAQ**TRY> (modified here and below so that this post and quoting responses do not show up in future searches) and below is a roundup of requests made since the last update and my initial thoughts on them.

I would appreciate any feedback, comments, suggestions, additions, alternatives, etc. that anyone feels like contributing prior to making any changes to the existing FAQ:-

<URL: http://jibbering.com/faq/ >

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="Use of javascript/Jscript at Win32 DOS prompt">

I believe that an entry in Section 4 of the FAQ would be worthwhile; just illustrating starting javascript-in-WSH from the command line and from, say, File Manager & Internet Explorer, and giving a well-chosen link or two.

It could include
<script type="text/javascript" src="include1.js"></script> & <script type="text/javascript"> ... </script><noscript> ... </noscript>
- they may be strictly HTML, but they are important to
Web use of javascript, and often given wrongly in the group.

Perhaps a possible <FAQ**TRY> could be composed here, if Jim would like to use such.

The FAQ has not been updated lately, and new expertise has come into the group. Might it be worth jointly reviewing one numbered part here each week, starting I suggest at 3.1 and working round to 2.12 then 3.1 again?

Re 3.1 - I find the Pocket Reference Flanagan very useful; it is cheaper & smaller.

Re 3.2 - Nothing to say about the intent, but I'd prefer <p> instead of <BR> before each subsubsection.

</quote>

I see an number of FAQ addition/modification requests here:-

1. The addition of a question on using/executing WSH/JScript for .BAT style (Windows) OS automation.

I will not be writing that entry as I have little experience of doing that so, though I am not opposed to the idea in general, I would need a more concrete proposal to start from. But I would also need to see some wider support for its inclusion, as it is not really a FAQ (just something that JavaScript authors might be inclined to employ/exploit).

2. Something on writing formal ((x)HTML DTD valid) script tags.

If that is the correct interpretation, it has been suggested a few times an I will return to it below.

3. Instigating a process of rolling review/modification of the FAQ section by section.

Having just gone through the FAQ requests for the last 7 months I think small regular updates might actually be easier but I am reluctant to commit myself to a rolling process, at least without evidence of general support for (and a willingness to contribute to) the process on the part a reasonable number of regulars in the group. (So if anyone else likes this idea, now it the time to say so).

4. The inclusion of:-
JavaScript Pocket Reference, by David Flanagan, pub. O'Reilly & Associates Inc. (Sebastopol, CA, US) 1998, ISBN 1-56592-521-1, 89 pages, £5.50.
-in the book recommendations in section 3.1.

I have never read (or to the best of my knowledge, set eyes upon) that book so I could not, in good conscience, make the decision one way or the other. But there are a lot of JavaScript books that I have not read so I will have to adopt a policy of not including book recommendations without widespread support (3 or more endorsements) for the books in questions (from people who's opinions I trust).

If anyone is in a position to express their opinion on the suitability of "JavaScript Pocket Reference" by David Flanagan for inclusion in the FAQ please do so. And, as usual, suggestion for other books that would be suitable for recommendation in the FAQ are also welcome (though authors of JavaScript books should probably consider the generally negative attitude within this group toward most existing JavaScript books, and therefor the possibility of generating negative publicity that might result form proposing volumes that may be considered unsuitable for inclusion in the FAQ).

5. Altering the HTML version of the FAQ so that Section 3.2 is marked up differently.

You propose P elements here and UL/LI in a later FAQENTRY request. I would agree that that section of the FAQ comes out a bit bunched up and could benefit from different mark-up but the HTML version of the FAQ is generated from the same XML file as the text versions that are posted to the group so changing the mark-up would involve re-writing (at least parts of) the script that generates the HTML from the XML. It looks like the change would be feasible but I was not planning to re-write Jim's scripts.

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="Stylistic concerns for large application">

If you had looked in the regularly -posted and -cited FAQ, you would have found no relevant occurrence of "include", which seems a pity.

Most of my javascript date pages use include files; but start at <URL:http://www.merlyn.demon.co.uk/js-index.htm#IF>, visit <URL:http://www.merlyn.demon.co.uk/js-nclds.htm> and <URL:http://www.merlyn.demon.co.uk/js-other.htm>.

<FAQ**TRY> - something on include files?

And perhaps the FAQ could link to an associated demonstration page, intended to be most illustrative under View Source??

Might FAQ 3.2 be more readable with <ul> ... <li> ... </ul> ?

</FAQ**TRY>

</quote>

By "include files" I assume you mean JS files referenced with the SRC attribute of script elements. I suppose that should mention what should be in those JS files (or rather what should be omitted, i.e. any HTML mark-up including script tags and HTML comments). How the SRC attribute would be written in a script tag (possibly that would be covered in an entry on the language attribute verses type="text/javascript") and go on to describe the possibility of document.write-ing (possibly dynamically constructed) script tags and maybe some alternatives such as createElement("script") etc.

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="parseInt .5">

I think you need to spend considerably more time reading and testing, and less time writing.

That function returns 50 for inputs of +5 & -5; and 00 for 0.

function LZ(x) {return(x<0||x>9?"":"0")+x} // for integers

is reliable, and has the possible advantage of always returning a string.

There is no leading zero function in the FAQ <FAQ**TRY> bur perhaps there should be; one so often sees repetitive coding for it.

<URL:http://www.merlyn.demon.co.uk/js-maths.htm#LZ> refers.
</quote>

I wonder if that could/should be slipped in at the end of 4.6 as that already discusses the generation of formatted number strings. Perhaps changing the question so that it is about less specific number formatting.

<quote
cite="http://groups.google.com/groups?selm=pldmFJG$7t4$Ewzt@merlyn ..demon.co.uk" author="Dr John Stockton" subject="javascript to create dynamic HTML? (Google AdSense)">
Hmmm, well, I'm not that fanatic, but... have you found any way to make mozilla use doublebuffering or to just paint over the old canvas instead of first clearing it? With the current implementation the date is flickering.

No. One reason is that I do not have, and probably have never seen, at least since 1996, Mozilla.

But if Mozilla does flicker in some or all sorts of rewrite, that could deserve a "how do I prevent it" <FAQ**TRY>, even if the answer is that it is not preventable.

IIRC, can one arrange, as for the Dynamic Graphic above the first button in <URL:http://www.merlyn.demon.co.uk/js-date3.htm>, that only the changed digits are rewritten? The date might then only flicker at midnight.

</quote>

I don't recall noticing any significant flickering problem with Mozilla/Gecko browsers and I don't see any flickering on js-date3.htm in or around the Dynamic Graphic while it is running.

<quote
cite="http://groups.google.com/groups?selm=3FDBC2B2.1020908@PointedEar s.de" author="Thomas 'PointedEars' Lahn" subject="window.opener.location.reload;">

Q: My script does not work. How do I make it work?

A: "Does not work" is a useless error description. [psf 4.11]
Suggestions?

If JavaScript support is present and enabled, debug the script.

Internet Explorer

Select Internet Settings, Extras(?; last tab), then

[X] Show script errors

To use a debugger:
[_] Disable script debugging

The Microsoft Script Debugger can be downloaded from
http://www.microsoft.com/downloads/details.aspx?FamilyId=E606E71F-BA7F-4 71E-A57D-F2216D81EC3D&displaylang=en

The How-To can be found at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sdbug/H tml/sdbug_1.asp

A script debugger is also included in Microsoft Visual Studio.

Netscape 3.x+ and
Mozilla/5.0 (incl. Netscape 6+, Mozilla Firebird, ...)

Type `javascript:' in the Location Bar to show the JavaScript Console.

Mozilla/5.0

In Mozilla, select Tools (menu), Web Development, JavaScript Console. In Netscape 6+, select Extras(?), Tasks(?), JavaScript Console.

Select Tools, Web Development, JavaScript Debugger. If Venkman, the JavaScript Debugger for Mozilla/5.0 is not yet installed, either update your Mozilla/5.0 and select `Debugger' in the Custom Setup, or download and install Venkman as Cross Platform Installation (XPI) from

<http://www.hacksrus.com/~ginda/venkman/>

How-Tos can be found there, too.

Opera

Select File, Preferences, Multimedia, then

[X] Enable JavaScript
[X] Open JavaScript console on error

$Foobar

RTFM.

</quote>

The first point: "Does not work" is a useless error description. Is a valid point and "does not work", as a bug report has deservedly been subject to a lot of criticism recently. I don't think that it should be addressed in the quick answers section but maybe 2.3 could be modified to stress the point.

Possibly re-wording the second paragraph of section 2.3 to read:-

<draft>
Please state your question as clearly and concisely as possible, as this will make it far easier for the other readers of the list to understand your problems and suggest possible solutions. Try to explain: 1. What you have done. 2. What you expected to happen. 3. What really happened. Use the Subject: of your post to indicate the type of problem you have, but include the question in the body as well. 'Help!' or 'I hate Netscape!' are not nearly as useful to contributors who do not read every post as 'parseInt("09")!=9'.
</draft>

The second suggestion strikes me as proposing an entry in section 4 that explains how to enable error reporting on at least the major browsers. Possibly with references to debuggers (though venkman is already referenced in section 3.2).

As usual that is not often specifically asked as a question but the information is frequently posted in replies so it probably does deserve consideration for a place in section 4.

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="Need help in validating the period in an email address (new JavaScript student)">

<FAQ**TRY> The FAQ should also say that, when asking about classwork, a poster needs to state that it is classwork (and to present what he/she has done so far, which you did).
</FAQ**TRY>

</quote>

That would be changes to section 2.3 again, but people asking about classwork is not that common (except just before the end of academic years/terms).

I don't want to include this as it addresses a small minority.

It might be worth suggesting that people explain the context in which they are asking their questions in the hope that they would mention when it was for an educational course but my experience suggests that often students are looking to have there homework done for them and know that admitting that it is homework would not produce their desired result.

Personally I like the approach to posts from students who are attempting to pass their homework of as a real web project that I first observed employed by Yep: posting a complete solution using such advanced techniques (closures, OO and full cross-browser support/fall-back) that no student who could not solve the original problem could hope to pass it off as their own work.

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="Javascript Daylight time problem...">
You use Date in several places. *Not* handling daylight saving is a very date specific act two times a year.

More often than that. Outside the EU, many countries (some quite respectable) change on different dates; some, such as Australia and New Zealand, have good reason for doing so. I think the EU change dates, surely the EU change-instants, are more commonly used than any others.

But at most twice per calendar year in any given location.

<FAQ**TRY> The FAQ is rather terse with its date advice; it might help if it had an explicit date-time question, and the one implicit in this thread might be good to choose.

</quote>

I can see some value in having a question that specifically relates to the use of the Date object, mostly to server as a way of channelling people interested in the Date object to more detailed information on the subject. Daylight saving might be a bit specialised (and maybe require too much code/explanation).

I suppose what we need is to find an expert of the Date object to come up with a *short* general question and answer on the Date object and some resources to reference for more details ;-)

<quote
cite="http://groups.google.com/groups?selm=20031019174853.28496.00001388 %40mb-m18.aol.com" author="HikksNotAtHome" subject="Client-side Javascript validation of "select multiple" for PHP ">

http://www.jibbering.com/faq/#FAQ4_25
Incorrectly states that are illegal characters in HTML. It was discussed not long ago and I believe the final concensus was that are in fact legal in the name.

</quote>

This one is very important as the FAQ should not be demonstrably incorrect. Currently it reads:-

4.25 My element is named myselect , how do I access it?

Form elements with any "illegal" characters can be accessed with formref.elements["myselect"] - These characters are illegal in the standard (x)HTML doctypes, so you should try to avoid them as browsers may perform incorrectly though.

The first "illegal" could stay as it could be argued that the characters are illegal in some contexts (JavaScript identifiers) but the second sentence must be re-worded. Maybe:-

<draft>
"These characters are illegal within ID attributes in the standard (x)HTML doctypes and javascript Identifiers, so you should try to avoid them as browsers may handle them incorrectly." </draft>

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="How to use window.open ?">

By composing text within a right margin of about 72 characters, in accordance with standard Usenet recommendation, you can make your material more readily readable to those with standard 72-column eyes or 80-column display windows.

<FAQ**TRY> Jim, I don't see a mention of posting margin or line-wrap in 2.3 </FAQ**TRY>.

</quote>

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="Need special kind of countdown timer ">

Please set your right margin at about 72 characters. It is easier to read, and quotes better in standards-compliant newsreaders. See references in FAQ. <FAQ**TRY> Mention margin in 2.3? </FAQ**TRY>

</quote>

Jim seems to be resistant to mentioning margins in section 2.3 and I am also inclined to leave that out. As it is there is a constant struggle to get people to follow the existing posting guidelines in section 2.3. The people who will not respect the existing guidelines are not going to be influenced by a specified margin and the people who do follow them don't seem to take much persuading to use a suitable margin.

<quote
cite="http://groups.google.com/groups?selm=fK6b+sBp0j6+EwiN@merlyn ..demon.co.uk" author="Dr John Stockton" subject="Force user to open in IE">
I'd like to know if there is a way to force a user to open a link on my page in I.E. even if they are using Netscape.?

Not even Bill Gates can do that directly.

Vcards are merely a source of annoyance for many readers.
<FAQ**TRY>?

</quote>

Of all the possible sources of annoyance? I am not inclined to include this.

<quote
cite="http://groups.google.com/[email protected]" author="Lasse Reichstein Nielsen" subject="dependable select boxes">

<FAQ**TRY>
You can add options to a select element using "selectRef.add" and remove them with "selectRef.remove", although these functions are not present in older browsers.

You need to keep the new data somewhere else, probably as an array of text/value pairs.

The following function changes the options of a select element:
---
function setOptions(selectRef,optArray) {
var optsRef = selectRef.options;
// Clear old options
optsRef.length = 0;
// Insert new options
for (var i = 0 ; i < optArray.length-1 ; i += 2) {
var opt = new Option(optArray,optArray[i+1]); // text,value optsRef[optsRef.length] = opt; } }
---
You can use this function from the onchange handler of another select element.
</FAQ**TRY>

</quote>

Successfully handling the manipulation of option elements in a select element is one of those things that probably deserves considerably more information than would fit well in a quick answer. There are always the design and fall-back/clean degradation issues in addition to the pure mechanics of creating and appending new Option elements.

<quote
cite="http://groups.google.com/groups?selm=TC$YsJEdhqC$EwXo@merlyn ..demon.co.uk" author="Dr John Stockton" subject="Question ">
What I'm trying to do is have the web page placed on a web server and have the list automatically update every time a file is uploaded. Is there a way to do that?? The list will be on the web page.

That requires server-side coding.

That's fully on-topic AIUI; OTOH the _default_ assumption here is that code is for execution in an Internet Web browser.
See FAQ 2.2 para 1.

<FAQNONENTRY> - Jim, I can't see the new FAQ on the Web. ???

<FAQ**TRY> At the end of that para, "... which host ..." - in the default case, where the javascript is used in a Web browser, a major point is that the author does not really know which host will be used. Could it be rephrased? "... which type of host ..." seems better but may not be best.

</quote>

Presumably "type of host" refers to web browsers, servers, WSH and others, while "host" alone might imply a single browser. I will change that, though I would be open to other alternative wordings.

<quote
cite="http://groups.google.com/groups?selm=20030827045359.11891.00000254 %40mb-m11.aol.com" author="HikksNotAtHome" subject="Scrolling Table - Which browsers support this code ">

http://www.metalusions.com/backstage/articles/8/

if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

<FAQ**TRY>
document.getElementById for IE4?
</FAQ**TRY>

Thoughts and comments?
Specifically, are there any cases where the above fails in IE4? Or, any other browsers that will pass the test other than IE4? I recall Jim mentioning one that supported document.all and document.layers at the same time.

</quote>

<quote
cite="http://groups.google.com/groups?selm=20030624173732.17796.00001037 %40mb-m15.aol.com" author="HikksNotAtHome" subject="Script Won't Upload in Netscape">

<FAQ**TRY>
http://www.metalusions.com/backstage/articles/8/ </FAQ**TRY>

I posted that URL a while back, don't remember if I offered it as an FAQEntry or not though.

if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

</quote>

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="prototyping document.getElementById">
I'm thinking of prototyping document.getElementById for those browsers that understand document.all but not document.getElementById (IE4).

Is that a reasonable thing to do? Suggestions?

Article
Subject: Re: Script Won't Upload in Netscape

included

if (document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

That looks worth a <FAQ**TRY> to me; and I put it in my <URL:http://www.merlyn.demon.co.uk/js-other.htm> as an example of Object Detection.

</quote>

I wonder whether including this is a good idea. I would handle IDed element retrieval with a specific function that either handled the fall-back from getElementById itself or had been set up during configuration to handle the fall-back. I generally don't like attempts to "normalise" browsers to a homogenised DOM.

Opinions?

<quote
cite="http://groups.google.com/[email protected]" author="Lasse Reichstein Nielsen" subject="Javascript in netscape navigator">

<FAQ**TRY>
Why doesn't the global variable "divId" refer to the
element with id="divId"?

It does in Internet Explorer, but not in *many* other browsers. The recommended way of referring to an element with id="foo" is document.getElementById("foo") In order to support older browsers that doesn't implement this W3C DOM method, fallback to proprietary features can be used. In Internet Explorer 4 (and WebTV?), you can use document.all["foo"] . In Netscape 4, maybe you can use document.layers["foo"] , but only if the element is absolutely positioned (or created with the Netscape 4 proprietary <layer> tag).

<URL:http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_access</FAQ**TRY>

</quote>

In one form or another this proposal is going into the FAQ. I originally proposed a longer alternative to Lasse's but Jim favoured making it considerably shorter and omitting all the references to fall-back.

My current version is:-

<draft>
4.41 Why doesn't the global variable "divId" always refer to the element with id="divId"?

A common shortcut(introduced by IE and reproduced in some other browsers) in accessing DOM elements that have ID attributes is to use a provided global variable with the same name as the element's ID string. However, the best approach is the document.getElementById method, which is part of the W3C DOM standard and implemented in modern browsers (including IE from version 5.0). So an element with id="foo" can be referenced with:-

var el = document.getElementById("foo");

<URL:http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_access</draft>

As usual, comments, criticisms, corrections and alternatives are welcome.

Having decided to remove Lasse's consideration of fall-back from this entry it might be worth re-considering Randy's IE 4 fall back for getElementById.

<quote
cite="http://groups.google.com/groups?selm=D25cBcE+0u8+EwC7@merlyn ..demon.co.uk" author="Dr John Stockton" subject="Downloadnig HTML source code">
File>Save As will give it to you, very easily, in MSIE's warped way of rendering but it adds some extra code to it and messes up the original folder organization. Netscape 7 seems to save it as it is sent by the server though.

Given the degree of variation in what people say happens (and that in what can happen), and the frequency with which viewing the source of a Web page is recommended in this group, ISTM that a <FAQ**TRY> on viewing source could be justified, perhaps adjacent to that on hiding source.

Perhaps a short paragraph outlining the possibilities, and if available a link to elsewhere.

FAQ 4.38 is rather brief, from the point of view of an off-line reader; could LB produce a sentence describing the basis?

</quote>

I am unsure what an entry on viewing source would say.
Server-scripters often don't seem to appreciate that debugging client-side JavaScript is better done using the source the browser receives instead of the server-script that generates it, but do that many people need to be told how to view the source?

4.38 will have to stay as it is unless Laurent (or someone else) comes up with an additional sentence (probably literally). And I suspect that the subject could not be usefully addressed in just one sentence, or any statement that was sufficiently short.

<quote
cite="http://groups.google.com/groups?selm=Lc$+rFC8alK$EwFy@merl yn.demon.co.uk" author="Dr John Stockton" subject="Script tag - language version">
Use the type attribute instead:

<script type="text/javascript">

<FAQ**TRY> That (slightly expanded) is now a FAQ candidate, IMHO.

</quote>

<quote
cite="http://groups.google.com/groups?selm=20031008225410.21542.00000503 %40mb-m02.aol.com" author="HikksNotAtHome" subject="Two Questions about the Following Block of Code">
<script language="JavaScript">
Language attribute is deprecated in favor of the type
attribute: text="type/javascript"

<FAQ**TRY>
type="text/javascript" in favor of language="javascript" </FAQ**TRY>

Not sure on a wording, but its seen a lot here :-(

</quote>

This certainly is frequently mentioned so it might deserve an entry.

So would the section 4 question be "How do I write HTML 4 valid script tags?" or "How do I write script tags?"? With the latter having to go into more detail on the LANGUAGE attribute (and possibly language version numbers and their associated problems).

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="Money Format Problem">

Revised <FAQ**TRY> 4.6

4.6 How to convert a Number into a String with exactly 2 decimal places?

For example, to format 6.57634 to 6.58, 6.5 to 6.50,
and 6 to 6.00?

Rounding of x.xx5 is uncertain, as such numbers are not represented exactly.

N = Math.round(N*100)/100 only converts N to a Number of value close to a multiple of 0.01; but document.write(N) does not give trailing zeroes.

ECMAScript Ed. 3.0 (JScript 5.5 (but buggy) and JavaScript 1.5) introduced N.toFixed, but that <test & describe what it does> .

Much code for trailing zeros fails for some numbers
(e.g. 0.07). The following works successfully :

BOX
BOX

Method toFixed in the box above is intended to do what
browser toFixed ought to do, not to be equivalent.

// Note that code I now use, at
<URL:http://www.merlyn.demon.co.uk/js-round.htm#GC>, differs a little from what is in the FAQ.

</quote>

The first request is to describe and test what toFixed actually does rather than just asserting that it is buggey in its implementations (4th paragraph). That sounds like it could be quite a large addition.

Adding a final note saying that the assigned
Number.prototype.toFixed function is not equivalent to the original doesn't strike me as necessary.

<quote
cite="http://groups.google.com/[email protected] emon.co.uk" author="Dr John Stockton" subject="New to java">
You do not need any javascript to do this. Just standard HTML with a bit of CSS to control the background image on mouseover.

There being questions which can quite reasonably be considered, /a priori/, to be javascript questions, but for which answers such as the above are appropriate, ISTM that it would be well <FAQ**TRY> for the FAQ to include, described as such, one or two links to well-written introductory CSS information.

</quote>

Perhaps an opportunity to assert the general principal that if something can be done without JavaScript then it should be done without JavaScript. I don't see an easy way of making that point, for example, suppose the question was "What is the best strategy for using JavaScript on the Internet?". That might certainly mention the preceding principal (and reference CSS as a result) along with such things as treating JavaScript as a means of providing optional enhancements and clean degradation. Then again it might just result in an extended argument about what the "best strategy" is.

Anyone care to start the ball rolling?

<quote
cite="http://groups.google.com/groups?selm=20030608204652.04207.00000619 %40mb-m01.aol.com" author="HikksNotAtHome" subject="FAQ Updates">

Any chance of an added entry on the problems, and possible solutions, to popup windows? Or even just links to articles on the problems with using it?

Whats wrong with window.open(...)?

</quote>

At the time I though that this suggestion deserved more consideration. The opening of windows with JavaScript certainly is frequently the subject of questions on the group and is frequently unwisely handled by script authors.

To start with we would need some resources to reference on the subject, and preferably not pages that gloss-over the problems of opening window. For that purpose Lasse Reichstein Nielsen's page:-

<URL: http://www.infimum.dk/HTML/JSwindows.html >

-is probably the best candidate that I have seen. While it is not as negative about the idea of opening new windows as I would be, it does not conceal the potential problems and even directly states that window opening is widely considered unsuitable for anything important. It would be nice to be able to also add a page on achieving pop-up like effects without using new browser instances (or modal dialogs).

The question it self could be fairly simple:-
<draft>
4.nn How do I open a new window with JavaScript?

New windows can be opened on browsers that support the
window.open function and are not subject to the action
of any pop-up blocking mechanism with code such as:-

if(window.open){
wRef = window.open("http://example.com/page.html", "windowName"); }

<URL; resource references>
</draft>

But there is a great deal omitted from the above, including any consideration of the window features list.

<quote
cite="http://groups.google.com/groups?selm=v0$3h1FuCs+$Ewzm@merl yn.demon.co.uk" author="Dr John Stockton" subject="Environment Variables in WSH JS">

Aside : <FAQ**TRY> 2.11 : "over 5 years" is IMHO ambiguous. Suggest "more than 5 years" or "for 5 years", whichever is meant.

</quote>

Yes, I will change that to "more than 5 years".

The code used in section 4.15 has come in for a lot of comment lately. While it is not the code I would use for the task, the existing code is short, will work successfully in browsers that support innerHTML and the text includes the pertinent caveats. So I am inclined to leave it as it is for the time being, unless a strong feeling that it should be changed (baring in mind the need for brevity) is expressed.

Richard.

[1] The only practical consequence is that I will not be offended if anyone feels like criticising/correcting my spelling and/or grammar. And I also won't object to suggestions of more concise wordings where available.
 

Dr John Stockton

Usenet Archive
Joined
Oct 10, 2001
Messages
3,778
Reaction score
0
JRS: In article <btfs7p$5gs$1$>, seen in
Richard Cornford
posted at Wed, 7 Jan 2004 02:51:35 :-

1. The addition of a question on using/executing WSH/JScript for .BAT style (Windows) OS automation.

I will not be writing that entry as I have little experience of doing that so, though I am not opposed to the idea in general, I would need a more concrete proposal to start from. But I would also need to see some wider support for its inclusion, as it is not really a FAQ (just something that JavaScript authors might be inclined to employ/exploit).

One reason for suggesting it is that I would like to have read such an entry, preferably a few years ago. However, the major point seems to be to say, more obviously than at present, that javascript (and VBscript) can be executed as Win32 programs, and with more capabilities than allowable in browsers. Most of what I know is at <URL:http://www.merlyn .demon.co.uk/batfiles.htm#WSH> (new Anchor).

The most important thing is to indicate that the possibility exists, better than 2.8 does at present.

If restructuring, one could start Sec.2 with a new 2.0 "What is javascript, and what is it for? - that would then absorb 2.6 & 2.7 & maybe 2.12 as subsubsections, and a slight enlargement of 2.8 sentence 3 to cover "what for".

"Javascript (and VBscript) can be used (a) in Web pages, which is the default assumption here; (b) in Intranet pages; (c) in Win32 with Windows Scripting Host, for general purposes; (d) in Web servers...; (e)
... ?"

By "include files" I assume you mean JS files referenced with the SRC attribute of script elements. I suppose that should mention what should be in those JS files (or rather what should be omitted, i.e. any HTML mark-up including script tags and HTML comments). How the SRC attribute would be written in a script tag (possibly that would be covered in an entry on the language attribute verses type="text/javascript") and go on to describe the possibility of document.write-ing (possibly dynamically constructed) script tags and maybe some alternatives such as createElement("script") etc.

Not necessarily as much as that in the FAQ itself. But a scan of the FAQ for include and for src finds nothing related. Perhaps no more need be said than the essence of <URL:http://www.merlyn.demon.co.uk/js- other.htm#Inc>.

That function returns 50 for inputs of +5 & -5; and 00 for 0.

function LZ(x) {return(x<0||x>9?"":"0")+x} // for integers

I wonder if that could/should be slipped in at the end of 4.6 as that already discusses the generation of formatted number strings. Perhaps changing the question so that it is about less specific number formatting.

IMHO, the item needs to be evident in sec. 4 of the index; i.e. in Subject(4.6).modified or under a new Subject.

I suppose what we need is to find an expert of the Date object to come up with a *short* general question and answer on the Date object and some resources to reference for more details ;-)

While Summer Time is not often asked about, it is quite often answered about.

Qn : Why does date ( differencing | incrementing ) go wrong?
Ans : Date is basically held as GMT, so date arithmetic across Summer Time transitions needs particular care. Examples :

(new Date('2004/11/01') - new Date('2004/10/01'))/864e5 // is 31.0416 new Date(new Date('2004/10/01').getTime+31*864e5).getDate // is 31 // Better examples may spontaneously appear.

Note that that the term "Summer Time" usefully introduces the string "Time" for search-fodder.

4.6 How to convert a Number into a String with exactly 2 decimal places?


Adding a final note saying that the assigned
Number.prototype.toFixed function is not equivalent to the original doesn't strike me as necessary.

The output of that function could be (a) equivalent to the original, or (b) equivalent to the bug-freed original, or (c) different.

ISTM important to discriminate between (a)|(b) & (c); if possibly (c), then I suggest calling the new function something slightly different, such as toFixxed, and adding in comment the word similar.

The code used in section 4.15 has come in for a lot of comment lately. While it is not the code I would use for the task, the existing code is short, will work successfully in browsers that support innerHTML and the text includes the pertinent caveats. So I am inclined to leave it as it is for the time being, unless a strong feeling that it should be changed (baring in mind the need for brevity) is expressed.

However, ISTM that the wording might be reconsidered, and the code of para 1 perhaps boxed.

I suggest that the FAQ could say that it classifies javascript versions in three (four) ways (a) Dead & gone (Javascript 1.0/1.1, IE & NS <=3, etc.? (a') Netscape 4.7 & compatibles ? (b) Elderly (c) Current & compatibles with (a) being forgotten (b) warnings of incompatibility, but not necessarily new solutions, expected (c) supported
 

Jim Ley

Usenet Archive
Joined
Nov 2, 1999
Messages
1,989
Reaction score
0
On Wed, 7 Jan 2004 16:47:09 +0000, Dr John Stockton
wrote:

If restructuring, one could start Sec.2 with a new 2.0 "What is javascript, and what is it for? - that would then absorb 2.6 & 2.7 & maybe 2.12 as subsubsections, and a slight enlargement of 2.8 sentence 3 to cover "what for".

"Javascript (and VBscript) can be used (a) in Web pages, which is the default assumption here; (b) in Intranet pages; (c) in Win32 with Windows Scripting Host, for general purposes; (d) in Web servers...; (e)

I'd ignore VBScript there. I'd also like to encourage SVG with it being mentioned, SVG is probably more popular than WSH for javascript use. (svg-developers mailing list for example often gets as many non-faq js questions as here.) but expanding what for might be good.

Jim.
 

Jim Ley

Usenet Archive
Joined
Nov 2, 1999
Messages
1,989
Reaction score
0
He had already
asked me if I was interested and I did volunteer, pointing out that because I am a dyslexic with a tendency to be long-winded[1]

People elsewhere have said that I have the worst grammar they have ever seen, so I don't think you can do any worse than me. Brevity can be forced on you once you realise how many lines the post is after processwenttxt.wsf is run.
I would appreciate any feedback, comments, suggestions, additions, alternatives, etc. that anyone feels like contributing prior to making any changes to the existing FAQ:-

<URL: http://jibbering.com/faq/ >

One possible suggestion was moving the domain of the FAQ to improve search engine placement, e.g. http://javascript-faq.jibbering.com/ or similar, I can host whatever but currently only have domains jibbering.com|org/spurn.org/svg-components.org to hand, it may not be wise due to the risk losing any google love we've got (google generally doesn't mind proper redirects to a new canonical url but...)
If anyone is in a position to express their opinion on the suitability of "JavaScript Pocket Reference" by David Flanagan for inclusion in the FAQ please do so.

Looking at it in Borders it's a broadly accurate pocket reference, if you want such a thing it's suitable, I'm not sure how useful it genuinely is though for someone looking to learn, but it does do what it says on the tin.

By "include files" I assume you mean JS files referenced with the SRC attribute of script elements.

Would also need to mentione "xlink:href" here for other non-HTML versions of script I think. (it's a FAQ elsewhere than here, and could be usefully addressed in a few words)
<draft>
"These characters are illegal within ID attributes in the standard (x)HTML doctypes and javascript Identifiers, so you should try to avoid them as browsers may handle them incorrectly." </draft>

I like this.
Successfully handling the manipulation of option elements in a select element is one of those things that probably deserves considerably more information than would fit well in a quick answer. There are always the design and fall-back/clean degradation issues in addition to the pure mechanics of creating and appending new Option elements.

It's amazing how much trouble this has been over the years...
<FAQNONENTRY> - Jim, I can't see the new FAQ on the Web. ???

This reminds me, I need to change the script, or tell you something else Richard, remind me if I forget.
I recall Jim mentioning one that supported document.all and document.layers at the same time.

Omniweb mentioned in
http://jibbering.com/faq/browsers.txt
Perhaps an opportunity to assert the general principal that if something can be done without JavaScript then it should be done without JavaScript.

I don't wholly agree with this, for example there are many things which CSS fails more disastrously at than the well authored javascript approach.
Then again it might just result in an extended argument about what the "best strategy" is.

Anyone care to start the ball rolling?

"Don't do anything that stops people accessing your content/using your site..."

There's my notes so far...

Jim.
 

HikksNotAtHome

Usenet Archive
Joined
Aug 10, 2002
Messages
1,154
Reaction score
0
In article <btfs7p$5gs$1$>, "Richard Cornford"
writes:

The second suggestion strikes me as proposing an entry in section 4 that explains how to enable error reporting on at least the major browsers. Possibly with references to debuggers (though venkman is already referenced in section 3.2).

As usual that is not often specifically asked as a question but the information is frequently posted in replies so it probably does deserve consideration for a place in section 4.

Another way to enable error messages in IE6:

Double click the Yellow ! in the lower left corner
Check the "Always display this message when an error occurs in the page" checkbox.

With the way that MS has changed the path to enable/disabling it in IE4/5/5.5/6, the above seems to be a simpler way to tell someone how to enable the error messages.

if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}

<--snip-->

I wonder whether including this is a good idea. I would handle IDed element retrieval with a specific function that either handled the fall-back from getElementById itself or had been set up during configuration to handle the fall-back. I generally don't like attempts to "normalise" browsers to a homogenised DOM.

Opinions?

I don't see where thats normalising the browser. To me, it simply makes it simpler to write scripts that fallback to IE4 instead of back to IE5 (unless its found to be defective in IE4 somewhere) by defining a function that works in IE4. Even with that snippet, the object detection routines should still be used to ensure that what you are trying to do works. It just seems easier than something like this:

if (document.getElementById){
//statements here
}
else if (document.all){
//same statements here but using document.all instead of // document.getElementById }

<--snip-->

4.38 will have to stay as it is unless Laurent (or someone else) comes up with an additional sentence (probably literally). And I suspect that the subject could not be usefully addressed in just one sentence, or any statement that was sufficiently short.

One thing that I have found out about Jims HTTPRequest page. I started tinkering with it on a whim, and found out (via Martin Honnen, <URL:
http://tinyurl.com/2f2hc /> is to the thread where he made it work in Mozilla for me. Not in the FAQ but if the FAQ links to a page that explains something, shouldn't we be able to critique that page as well? (Sorry Jim)

<--snip-->

<FAQ**TRY>
type="text/javascript" in favor of language="javascript" </FAQ**TRY>

Not sure on a wording, but its seen a lot here :-(

</quote>

This certainly is frequently mentioned so it might deserve an entry.

So would the section 4 question be "How do I write HTML 4 valid script tags?" or "How do I write script tags?"? With the latter ...

"Should I use the language attribute or the type attribute in my script tags?"

And as they say, thats my 2 cents worth of thoughts. Although I am not as verbose, my tendency is in the opposite direction and probably not verbose enough.
 

Dr John Stockton

Usenet Archive
Joined
Oct 10, 2001
Messages
3,778
Reaction score
0
JRS: In article , seen in
Jim Ley posted at Wed, 7
Jan 2004 22:56:04 :-
> If anyone is in a position to express their opinion on the
> suitability of "JavaScript Pocket Reference" by David Flanagan
> for inclusion in the FAQ please do so.

Looking at it in Borders it's a broadly accurate pocket reference, if you want such a thing it's suitable, I'm not sure how useful it genuinely is though for someone looking to learn, but it does do what it says on the tin.

Don't underestimate the advantage of it being only 175*107*8 mm and corresponding weight. As a source of reminder, it's very handy; for example if (after experience on other languages, one wants to discover why Math.trunc does not work as expected (trunc is spelt floor in JS). Just "(has pocket version)" would suffice.

If that was the Kingston Borders, pray mail me where to look in it; I prefer Dillons there.
 

Richard Cornford

Usenet Archive
Joined
Aug 17, 2002
Messages
6,000
Reaction score
0
Another way to enable error messages in IE6:

Double click the Yellow ! in the lower left corner
Check the "Always display this message when an error occurs in the page" checkbox.

With the way that MS has changed the path to enable/disabling it in IE4/5/5.5/6, the above seems to be a simpler way to tell someone how to enable the error messages.

I was thinking much the same. I would be worth quickly mentioning that it was also available for activation under one of the menus but paths through menus and dialogs are not as easy to describe (especially as text).

I would also favour describing typing "javascript:" into the location bar on Netscape/Mozilla/Gecko browsers rather than going into details on the menus and preferences dialogs.
if(document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id];
}
}
I wonder whether including this is a good idea. I would handle IDed element retrieval with a specific function that either handled the fall-back from getElementById itself or had been set up during configuration to handle the fall-back. I generally don't like attempts to "normalise" browsers to a homogenised DOM.

Opinions?

I don't see where thats normalising the browser. To me, it simply makes it simpler to write scripts that fallback to
IE4 instead of back to IE5

Well, its just one feature so it is a bit extreme to call it normalising, but it is a step (albeit a small one) in that direction.
(unless its found to be defective in IE4 somewhere)

I can only see this code failing to be equivalent to getElementById if there are multiple elements with the same ID on a page, or when an element has the same string assigned to its NAME attribute as has been assigned to the ID of a different element. The first is invalid HTML (which IE puts up with) and the second is actually a problem for some IE implementations of getElementById anyway.
by defining a function that works in IE4. Even with that snippet, the object detection routines should still be used to ensure that what you are trying to do works. It just seems easier than something like this:

if (document.getElementById){
//statements here
}
else if (document.all){
//same statements here but using document.all instead of // document.getElementById }

Yes its easier than that, but recognising that the task that needs to be handled differently on different browsers is just the IDed element retrieval would suggest that just that task could be handed off to a separate dedicated function so there is no repetition of blocks of statements in the branches for each condition.

As the above function is just an easy way of handling fall-back for browsers that have a document.all collection but no getElementById method I still don't want to give it a dedicated entry in section 4 (at least without some discussion of similar fall-back for other known browsers. On the other hand, see my proposal for 4.15 in my reply to Dr John Stockton for one possible compromise.

shouldn't we be able to critique that page as well? (Sorry Jim)

Changing that page is outside of my remit. :)

"Should I use the language attribute or the type attribute in my script tags?"
<snip>

Maybe "and/or" instead of "or". That would narrow the question down quite a bit, and so make for a short answer. It would also be a very (x)HTML browser specific answer. I was wondering whether it would be practical to address Dr John Stockton's concerns about including files within this entry, but that won't be possible if it is narrowed down to just the attributes.

Hmm, I might just have to write some versions and see what people think.

Thanks for your thoughts.

Richard.
 

Richard Cornford

Usenet Archive
Joined
Aug 17, 2002
Messages
6,000
Reaction score
0
People elsewhere have said that I have the worst grammar they have ever seen, so I don't think you can do any worse than me.

The extent to which my grammar may be acceptable is more a result of having articulate parents and decades of listening to BBC Radio 4 than anything the British education system can claim credit for. I don't know any formal English grammar rules, I don't recall any of my school "English teachers" ever mentioning anything substantial relating to their subject at all.
Brevity can be forced on you once you realise how
many lines the post is after processwenttxt.wsf is run.

I am very aware of the risk (and consequences of) bloating the FAQ. :)

One possible suggestion was moving the domain of the FAQ to improve search engine placement, e.g. http://javascript-faq.jibbering.com/ or similar, I can host whatever but currently only have domains jibbering.com|org/spurn.org/svg-components.org to hand, it may not be wise due to the risk losing any google love we've got (google generally doesn't mind proper redirects to a new canonical url but...)

When you where debating this with Dr John Stockton (on
microsoft.public.scripting.jscript as I recall) I did a google search and the FAQ came out 4th, which didn't seem too bad (or as bad as Dr John Stockton's attempt).
Looking at it in Borders it's a broadly accurate pocket reference, if you want such a thing it's suitable, I'm not sure how useful it genuinely is though for someone looking to learn, but it does do what it says on the tin.

Maybe someone with the 2nd or 3rd edition of JavaScript: The Definitive Guide might want an up to date reference without the rest of the book, but I agree that it is not a book for learners of JavaScript. I am still not inclined to include it.

This reminds me, I need to change the script, or tell you something else Richard, remind me if I forget.
OK.

I don't wholly agree with this, for example there are many things which CSS fails more disastrously at than the well authored javascript approach.

You are thinking of things like the CSS "alternative" to, say, image rollover scripts that aren’t (yet) nearly as well supported as the JavaScript approach? I was thinking more of things like using JavaScript to detect the browsers and then choose a stylesheet to reference in link elements (often with no default for when JavaScript is not available), which is something I think is better addressed with CSS alone.
"Don't do anything that stops people accessing your
content/using your site..."

In which "(or search engine robots)" cold be inserted after "people", if they could be said to "use" a site.
There's my notes so far...

Thanks, I still have plenty to think about before settling on any final changes.

Richard.
 

Richard Cornford

Usenet Archive
Joined
Aug 17, 2002
Messages
6,000
Reaction score
0
"Dr John Stockton" wrote:

<snip>
The most important thing is to indicate that the possibility exists, better than 2.8 does at present.

OK.

If restructuring, one could start Sec.2 with a new 2.0
"What is javascript, and what is it for? - that would then absorb 2.6 & 2.7 & maybe 2.12 as subsubsections, and a slight enlargement of 2.8 sentence 3 to cover "what for".

"Javascript (and VBscript) can be used ...
<snip>

I will have to mull that over a bit and consider Jim's suggestion of mentioning SVG, but I have no intention of mentioning VBScript (I'll leave that for VBScript groups).

<snip>
Not necessarily as much as that in the FAQ itself. But a scan of the FAQ for include and for src finds nothing related. Perhaps no more need be said than the essence of <URL: http://www.merlyn.demon.co.uk/js-other.htm#Inc >.

As I said, I was thinking SRC could get into an entry on writing formal script tags, but Randy is interested in stressing the type V language attribute aspect so I will have to see where that goes.

>That function returns 50 for inputs of +5 & -5; and 00 for 0.
>
> function LZ(x) {return(x<0||x>9?"":"0")+x} // for integers

>I wonder if that could/should be slipped in at the end of 4.6 as ...
<snip>
IMHO, the item needs to be evident in sec. 4 of the index; i.e. in Subject(4.6).modified or under a new Subject.

I will start pulling that together into a proposal for 4.6 shortly.

<snip>
While Summer Time is not often asked about, it is quite often answered about.

True, but I was wondering if there might be something more often asked/answered about Date. But if the point is channel people interested in the Date object towards more information by reference then it isn't vital which Date question is answered in the FAQ.

Qn : Why does date ( differencing | incrementing ) go wrong?
Ans : Date is basically held as GMT, so date arithmetic across Summer Time transitions needs particular care. Examples :

GMT or UTC (strictly)?

(new Date('2004/11/01') - new Date('2004/10/01'))/864e5 // is 31.0416 new Date(new Date('2004/10/01').getTime+31*864e5).getDate // is 31 // Better examples may spontaneously appear.

spontaneously appear? :)

Note that that the term "Summer Time" usefully introduces the string "Time" for search-fodder.

In terms of the natural translation into English of the concept in other languages (and its use in various English speaking cultures), is "summer Time" preferable to "Daylight Saving Time" (either would introduce "Time" as a search term)? It is not that easy for me to tell because I habitually use "summer Time" in a UK context.

>4.6 How to convert a Number into a String with exactly 2
> decimal places?
> ...

>Adding a final note saying that the assigned
>Number.prototype.toFixed function is not equivalent
>to the original doesn't strike me as necessary.

The output of that function could be (a) equivalent to the original, or (b) equivalent to the bug-freed original, or (c)
different.

...

Would you be satisfied with a JavaScript comment in the code block?

<snip>
>The code used in section 4.15 has come in for a lot
> of comment lately. ...
<snip>
However, ISTM that the wording might be reconsidered, and the code of para 1 perhaps boxed.

There are two separate sections of code in paragraph 1 (HTML and JavaScript) and they seem to me to be too short to warrant a box of their own. Re-wording is worth considering, how about:-

<draft>
4.15 How do I modify the current page in a browser?

Modern dynamic browsers (including IE4+ and NS6+) with the - innerHTML - extension allow new HTML code to be assigned to the content of elements. With original HTML such as <div id="anID">some content</div> the contents of the div element could be replaced with:
document.getElementById("anID").innerHTML="Some <em>new<\/em> Content";

if((!document.getElementById) && document.all){
document.getElementById =
new Function("id", "return document.all[id];"); } // emulate getElementById on document.all only browsers.

if(document.getElementById){
DynWrite=new Function("id", "S",
"document.getElementById(id).innerHTML=S; return true"); }else{ DynWrite=new Function("return false;"); }

The above code is ineffective but (quietly) harmless on browsers that do not support the required features. NS4 also allows some re-writing of the current page but has serious issues and is not covered here. Also, browsers are increasingly supporting standardised methods for creating and inserting new elements/nodes into the DOM tree, which can be used to similar effect.

<existing links to innerHTML info>
<new link to W3C core DOM refs., or a good page on
createElement/appendChild approach (suggestions?)>
</draft>

Slightly longer over all.

I said that I would not re-write Jim's code but the above is functionally equivalent, slightly shorter and provides an opportunity to slip Randy's IE4 support for getElementById (though in a Function constructor form) in without dedicating a separate question to it.

I have also added a word on the W3C DOM createElement approach. Hopefully that will placate some of the objectors to the use of innerHTML, one of whom might care to find a good page to reference on the subject (rather than the W3C specs).

I suggest that the FAQ could say that it classifies javascript versions in three (four) ways (a) Dead & gone (Javascript 1.0/1.1, IE & NS <=3, etc.? (a') Netscape 4.7 & compatibles ? (b) Elderly (c) Current & compatibles with (a) being forgotten (b) warnings of incompatibility, but not necessarily new solutions, expected (c) supported

That looks like it could be a footnote to section 4, I will think about it.

Thanks for the (and future) feedback.

Richard.
 

Dr John Stockton

Usenet Archive
Joined
Oct 10, 2001
Messages
3,778
Reaction score
0
JRS: In article <btl7ae$4oj$1$>, seen in
Richard Cornford
posted at Fri, 9 Jan 2004 03:31:25 :-
I can only see this code failing to be equivalent to getElementById if there are multiple elements with the same ID on a page, or when an element has the same string assigned to its NAME attribute as has been assigned to the ID of a different element. The first is invalid HTML (which IE puts up with) and the second is actually a problem for some IE implementations of getElementById anyway.

A warning along the lines of "Here, it is safest to have the ID different from any other ID or NAME on the page; it is generally unwise to repeat identifications unnecessarily, except for experts." might suffice.

That's not a bad rule in general; for example, if a page has two distinct instances of a matching label in circumstances where all browsers can tell them apart, it is still possible for the programmer to start editing the wrong one.
 

Dr John Stockton

Usenet Archive
Joined
Oct 10, 2001
Messages
3,778
Reaction score
0
JRS: In article <btl7ak$4on$1$>, seen in
Richard Cornford
posted at Fri, 9 Jan 2004 03:31:32 :-
"Dr John Stockton" wrote:

>Qn : Why does date ( differencing | incrementing ) go wrong?
>Ans : Date is basically held as GMT, so date arithmetic across
> Summer Time transitions needs particular care. Examples :

GMT or UTC (strictly)?

Strictly, I believe, UT. But that looks like a misprint for UTC. UTC has leap seconds, and is therefore inappropriate for ordinary computer work, where they are ignored. GMT is very widely understood, with a meaning matching the circumstances. No ordinary computer keeps time accurately enough for the difference between any "similar" scales to matter. The differences that matter are caused by Time Zone, Summer Time, and Just Plain Being Wrongly Set (and, for a few, by the difference between sidereal & solar time, which is about one part in
365).

Therefore, I tend to use GMT in text, and the UTC functions in code; it has the advantage that I can search independently for code & text references.

However, considering automated searches, if the FAQ says enough about date to include one of GMT & UTC, it should have both : "... held as GMT/UTC, so ..." conveys appropriate ambiguity. For the knowledgeable, perhaps include /UT.

>(new Date('2004/11/01') - new Date('2004/10/01'))/864e5 // is 31.0416
>new Date(new Date('2004/10/01').getTime+31*864e5).getDate // is 31
>// Better examples may spontaneously appear.

spontaneously appear? :)

In the newsgroup. There have been many in the past.

> >4.6 How to convert a Number into a String with exactly 2
> > decimal places?
> > ...
>
>>Adding a final note saying that the assigned
>>Number.prototype.toFixed function is not equivalent
>>to the original doesn't strike me as necessary.
>
>The output of that function could be (a) equivalent to the
>original, or (b) equivalent to the bug-freed original, or (c)
>different.
>
...

Yes; it has the advantage of possibly appearing in the code used.

<snip>
>>The code used in section 4.15 has come in for a lot
>> of comment lately. ...
<snip>
>However, ISTM that the wording might be reconsidered, and
>the code of para 1 perhaps boxed.

There are two separate sections of code in paragraph 1 (HTML and JavaScript) and they seem to me to be too short to warrant a box of their own. Re-wording is worth considering, how about:-

<draft>
...

I do NOT like quietly ineffective code. Failing to work CANNOT be assumed harmless by a FAQ maintainer; that is a programmer or page- designer decision.

But ISTM that by replacing }else{ ... } in the above with something like

}
if (!DynWrite) {
alert("Element replacement not available in this browser.\n" + "Display likely to be partially incorrect.") DynWrite=new Function("return false;")
}

then a clear warning is given to the mere reader of the FAQ, and is evident to the copy'n'paster of the material. It is also obvious that a reader of the page may get an alert, and obvious how to prevent that.

The additional overhead of if (!DynWrite) as opposed to else must be insignificant.

That which is at present in the FAQ works for me, presuming that my holidays.htm works for near enough everyone; elsewhere, I use something similar. I would change to new FAQ code if I knew that the new code works with MSIE4 and with at least as many later browsers as the old.
 

Jim Ley

Usenet Archive
Joined
Nov 2, 1999
Messages
1,989
Reaction score
0
On Fri, 9 Jan 2004 03:31:32 -0000, "Richard Cornford"
wrote:

"Dr John Stockton" wrote:

<existing links to innerHTML info>
<new link to W3C core DOM refs., or a good page on
createElement/appendChild approach (suggestions?)>
</draft>

I'm actually quite reluctant to incude createElement/setAttribute as they're not needed in current browsers, and future browsers will be namespace aware so the namespace aware versions such as createElementNS will be required, and teaching createElement will just confuse people even more.

Of course I'm well known for not being a fan of DOM 1, and the amount of questions it generates is the main reason.

I said that I would not re-write Jim's code

rewrite any of it, it's at least 4 years old, and grew out of a need to support NN4, change it however!

Jim.
 

Jim Ley

Usenet Archive
Joined
Nov 2, 1999
Messages
1,989
Reaction score
0
When you where debating this with Dr John Stockton (on
microsoft.public.scripting.jscript as I recall)

Was it, I'm not currently reading there, although I did for awhile again on the wine covered laptop, I guess it could've been then.
I did a google search
and the FAQ came out 4th, which didn't seem too bad (or as bad as Dr John Stockton's attempt).

I'd've thought http://javascript-faq.jibbering.com/ that kept the current google love of the FAQ would get even better than that, but I'm not sure it's really worth the trouble, especially as it's extra risk of me forgetting to set up the vhosts if I change/reinstall servers and server is getting a new disk real soon now, well when I can get one shipped down there, and get it nstalled it, it's currently very ill, new server sometime soon. Okay, not really a new server, a wine covered laptop...

Jim.
 

Jim Ley

Usenet Archive
Joined
Nov 2, 1999
Messages
1,989
Reaction score
0
One thing that I have found out about Jims HTTPRequest page. I started tinkering with it on a whim, and found out (via Martin Honnen, <URL:
http://tinyurl.com/2f2hc /> is to the thread where he made it work in Mozilla for me.

Hey, c'mon I wrote it almost 2 years ago, and I'm still not interested enough in mozilla outside web security to bother looking into it. I'll update it to point to the thread, at some point, if I find some bandwidth.
Not in the FAQ but if the FAQ links to a page that explains something, shouldn't we be able to critique that page as well? (Sorry Jim)

My pages can always be critiqued, they're basically rubbish, not only that, but patches are always welcome, and sometimes even apply them :)

Jim.
 

Jim Ley

Usenet Archive
Joined
Nov 2, 1999
Messages
1,989
Reaction score
0
On Fri, 9 Jan 2004 20:00:08 +0000, Dr John Stockton
wrote:

I do NOT like quietly ineffective code.

then you shouldn't be authoring for the web, your code has to be able to cope with that situation, as it's always one of the options.

Failing to work CANNOT be
assumed harmless by a FAQ maintainer; that is a programmer or page- designer decision.

Then there's no possible code we could use.

alert("Element replacement not available in this browser.\n" + "Display likely to be partially incorrect.")

So making completely unwarranted assumptions about the existance of alert... Also of course it's completely un-understandable to users.

then a clear warning is given to the mere reader of the FAQ, and is evident to the copy'n'paster of the material.

The warning I believe is more than sufficient, I'm still reluctant to have 4.15 in at all.

Jim.
 

John G Harris

Usenet Archive
Joined
Oct 17, 2001
Messages
1,121
Reaction score
0
In article <8LHDu3KIhw$$>, Dr John Stockton
writes
JRS: In article <btl7ak$4on$1$>, seen in
Richard Cornford
posted at Fri, 9 Jan 2004 03:31:32 :-
<snip>
>GMT or UTC (strictly)?

Strictly, I believe, UT. But that looks like a misprint for UTC.
<snip>

Strictly, none of these. You will find a refreshingly clear, as well as accurate, account of calendar and time systems at

<URL:http://www.npl.co.uk/time/time_scales.html>

Javascript date objects use a rule for allocating each second to a particular minute/hour/day/month/year that hasn't got an official name. Approximate local time is as good a description as any.

John
 

Richard Cornford

Usenet Archive
Joined
Aug 17, 2002
Messages
6,000
Reaction score
0
"Dr John Stockton" wrote:

<snip>
>>... : Date is basically held as GMT, ...
<snip>
>GMT or UTC (strictly)?

Strictly, I believe, UT. But that looks like a misprint for UTC. UTC has leap seconds, and is therefore inappropriate for ordinary computer work, ...
<snip>
However, considering automated searches, if the FAQ says enough about date to include one of GMT & UTC, it should have both :
"... held as GMT/UTC, so ..." conveys appropriate ambiguity. For the knowledgeable, perhaps include /UT.

The spec says:-
<quote cite="ECMA 262 3rd edition">
15.9.1.1 Time Range
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC. Leap seconds are ignored. It is assumed that there are exactly 86,400,000 milliseconds per day. ...

...

The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.
</quote>

But I like "conveys appropriate ambiguity" (and agree that GMT might be useful for searching), though I probably will put UTC first.

<snip>
>The above code is ineffective but (quietly) harmless on browsers
>that do not support the required features.

I do NOT like quietly ineffective code. Failing to work CANNOT be assumed harmless by a FAQ maintainer; that is a programmer or page- designer decision.

I don't like quietly harmless code either, I want code to actively know that what it intends to do will fail or has failed, so it is in a position to fall-back/cleanly degrade under control. But when it comes to using JavaScript for inserting content into HTML that becomes quite involved, and often very specific to the problem situation.

I added the comment because I though that readers of the FAQ might appreciate being tipped of that the code is not a panacea. But there isn't a content inserting panacea as there are numerous browsers that are just not that dynamic (and, of course, nothing can be inserted without JavaScript[1]).

But ISTM that by replacing }else{ ... } in the above with something like

}
if (!DynWrite) {
alert("Element replacement not available in this browser.\n" + "Display likely to be partially incorrect.") DynWrite=new Function("return false;")
}

Unfortunately it is not a simple as that. The branch that generates the - return false; - function is guaranteed to never be able to insert content (because it has no mechanism for retrieving the element references) but the other branch is a long way from guaranteed success. On Opera 6, for example, it will assign a new string property to the element, but that will not alter the page or DOM tree in any way (harmless, but ineffective).

then a clear warning is given to the mere reader of the FAQ,

Which is what I was attempting.

and is evident to the copy'n'paster of the material. It is also obvious that a reader of the page may get an alert, and obvious how to prevent that.

I suspect that the copt'n'paste merchants actively don't want to understand what they are doing (witness George Hester) and are likely to leave the alert in place.

else The additional overhead of if (!DynWrite) as opposed to must be insignificant.

For the logic of the situation the - else - seems fine to me.

That which is at present in the FAQ works for me,

My version of Jim's code is logically identical. It will behave identically to the original. The only difference is that because it uses Randy's getElementById emulation to create a document.getElementById function on IE4 (and maybe others) it will produce a knock-on effect of convincing other scripts that misguidedly make inferences about features beyond getElementById based on its existence that they are looking at a browser similar to IE 5+. But as we recommend against object inference probably that is an effect that does not need to be worried about.

presuming that my holidays.htm works for near enough
everyone; elsewhere, I use something similar.

It's a page design decision, and it's yours to make. The script (Jim's and mine) will work on JavaScirpt capable browsers that support the innerHTML extension. That is the largest sub-set of browsers on which it is possible to insert content dynamically.

I would change to new FAQ code if I knew that the new code works with MSIE4 and with at least as many later browsers as the old.

There is no reason that it should not work on exactly as many browsers as the previous version because it doesn't do anything any differently.

Richard.

[1] Except that CSS has some content inserting behaviour in its latter versions, but not implemented in many browsers yet. And if CSS is optional then any content inserted with it also has to be optional. (But much the same is true of JavaScript.)
 

Richard Cornford

Usenet Archive
Joined
Aug 17, 2002
Messages
6,000
Reaction score
0
"Jim Ley" wrote:

<snip>
I'm actually quite reluctant to incude createElement/setAttribute as they're not needed in current browsers, and future browsers will be namespace aware so the namespace aware versions such as createElementNS will be required, and teaching createElement will just confuse people even more.

That is a very good point. I was recently thinking about the NS versions of the core DOM functions in relation to the occasionally promoted suggestion that Core DOM should be used instead of HTML DOM methods because it would facilitate future-compatibility with XHTML implementations. But for XHTML the code is going to have to be re-written for the NS functions anyway, making the future compatibility argument a bit hollow.

I don't have a problem with dropping that last sentence (and the reference). So it's over to the DOM supporters to convince me to include it. :)

Of course I'm well known for not being a fan of DOM 1, and the amount of questions it generates is the main reason.

>I said that I would not re-write Jim's code

rewrite any of it, it's at least 4 years old, and grew out of a need to support NN4, change it however!

Ok, in that case the Function constructors are going to be changed to function expressions. Which means that Randy's getElementById emulation will get to revert to its original form. As I understand it the Function constructors are to avoid syntax errors in ancient language version, and if we stop actively supporting Netscape 4 it doesn't seem unreasonable to assume that the code will never be seen by even older browsers.

Richard.
 

Dr John Stockton

Usenet Archive
Joined
Oct 10, 2001
Messages
3,778
Reaction score
0
JRS: In article <btqcpe$qmq$1$>, seen in
Richard Cornford
posted at Sun, 11 Jan 2004 02:35:15 :-
"Dr John Stockton" wrote:

The spec says:-
<quote cite="ECMA 262 3rd edition">
15.9.1.1 Time Range
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.

Should of course include "the start of" or "0h" or similar; 1 ms from 1 Jan 70 was at 00:00:00.001 in 2 Jan 1970.

Leap seconds are ignored. It is assumed that there are
exactly 86,400,000 milliseconds per day. ...

That's certainly a wrong thing to put, of course, to say "per UTC day" would at least be consistent.

...

The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.
</quote>

That is acceptable; but the time scale that it defines is not UTC (however, I suspect that UTC may not have been defined in 1970).

But I like "conveys appropriate ambiguity" (and agree that GMT might be useful for searching), though I probably will put UTC first.

I added the comment because I though that readers of the FAQ might appreciate being tipped of that the code is not a panacea. But there isn't a content inserting panacea as there are numerous browsers that are just not that dynamic (and, of course, nothing can be inserted without JavaScript[1]).

>But ISTM that by replacing }else{ ... } in the above
>with something like
>
> }
> if (!DynWrite) {
> alert("Element replacement not available in this browser.\n" + ...

It is not harmless if the coder put a false statement in a Div expecting it to be over-written.

ISTM that an inability to warn in some circumstances does not justify failing to warn in circumstances when the failure is easily detected. But if there is any code or comment or text warning in the FAQ, then code plus comment plus text should between them warn of all known possible failures, even if it is necessary to resort to text like "in some browsers this fails undetectably".

>then a clear warning is given to the mere reader of the FAQ,

Which is what I was attempting.

>and is evident to the copy'n'paster of the material. It is
>also obvious that a reader of the page may get an alert, and
>obvious how to prevent that.

I suspect that the copt'n'paste merchants actively don't want to understand what they are doing (witness George Hester) and are likely to
^^^^^^^^^^^^^
No; until I see reason to believe that his style has changed to conform with Usenet standards, I'll not witness that; but it's easy to believe.

leave the alert in place.

In that case they should find it in testing, if it is a well-tested site; or someone else will find it for them. Even code in a FAQ should be scrutinised before use, and preferably understood.

After all, the existing code has side-effects; it replaces any previous value in DocDom, GetRef, etc. A user should give himself an opportunity to notice that.

[1] Except that CSS has some content inserting behaviour ...

I think you can reasonably safely say that nothing can be inserted by javascript in a browser which is not running javascript.

Perhaps the example in the FAQ should have HTML resembling <div ID=XXX>This should not remain here.</div>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,050
Messages
3,104,249
Members
248,133
Latest member
DujonT

Latest Threads

Top