c o m p . l a n g . j a v a s c r i p t    M E T A - F A Q

   _________________________________________________________________

                 T A B L E   O F   C O N T E N T S
                 =================================
 
    1 meta-FAQ  meta-questions

    2 comp.lang.javascript tips

            2.1 Which newsgroup deals with javascript?
            2.2 What questions are off-topic for clj?
            2.3 Why did I get flamed when I posted to clj?
                What do I have to do before posting to clj?
            2.4 Why was my post not answered?
            2.5 How do I direct someone to this FAQ?
            2.6 What is ECMAScript? JScript?
            2.7 What are object models?
            2.8 What is the document object model?
            2.9 Internationalisation in javascript.
            2.10 I have a question that is not answered in
                here or in any of the resources mentioned here
                but I'm sure it has been answered in clj. Where
                are the clj archives located?
            2.11 What does the future hold for ECMAScript?
    
    3 javascript resources

            3.1 What books cover javascript?
            3.2 What online resources are available?
            3.3 Is there a javascript games site?

    4 Quick Answers

     4.1 How do I protect my javascript code/disable
  right mouse button?
     4.2 How can I disable the back button in a web browser?
     4.3 How can I access the client-side filesystem?
     4.4 How can I see in javascript if a web browser 
  accepts cookies?
     4.5 How can I protect a webpage in javascript?
     4.6 How do I format 6.57634 to 6.58 or 6.5 to 6.50?
     4.7 Why does 5 * 1.015 != 5.075?
     4.8 How do I communicate between frames in a web browser?
     4.9 How do I find the size of a browser window?
     4.10 How do I check to see if a childwindow is open, before opening another?
     4.11 Why does framename.print() not print the right frame in IE?
     4.12 Why does parseInt(09) give an error?
     4.13 How do I get the value of a SELECT box in NN?
     4.14 How do I close a window and why does it not work on the first one?
     4.15 How do I modify the current page in a browser?

    5 Comments
    _________________________________________________________________


1.0 meta-FAQ meta-questions
===========================

   You are reading the __ comp.lang.javascript __ meta-FAQ, version 6.40

    This is the official __ comp.lang.javascript __ (clj) FAQ. 
    Or, more accurately, the meta-FAQ as it mainly provides URLs
    to further information about javascript and some hints and tips
    to make your stay in comp.lang.javascript more enjoyable.

    This document was created to help reduce the high
    levels of noise on clj and to provide a resource for people new
    to javascript or who want to know locations of valuable
    javascript resources.

    The FAQ will currently be posted on Monday, Wednesday and Friday,
    until such a time as the regulars feel it can be posted less 
    frequently.
     
    It is also available on the web at 

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

2.0 comp.lang.javascript tips
=============================

  2.1 Which newsgroup deals with javascript?

    __ comp.lang.javascript __ 
    is the official Usenet newsgroup dealing with javascript. There
    are other newsgroups but many of them are not carried by most
    news feeds. clj is an unmoderated newsgroup.

  2.2 What questions are off-topic for clj?

    clj deals with ECMAScript languages, so any questions about
    JavaScript or JScript are welcome - however the group has a 
    majority of questions about using javascript in a browser,
    please make it obvious which host you are using javascript in. 

    Javascript and Java are two completely different
    languages. Java questions should be asked in one of the
    comp.lang.java.* newsgroups; they are not appropriate for clj.

    Questions dealing with other scripting languages,
    such as VBScript, PerlScript or CGI scripting are also off-topic,
    as are HTML-only questions.

  2.3 Why did I get flamed when I posted to clj?
      What do I have to do before posting to clj?

    Before posting to clj, you should thoroughly read this
    document. You should also thoroughly read the resources mentioned
    in section 3. Read FYI28/RFC1855, on Usenet and/or
    http://www.jsiinc.com/newsgroup_document.htm
    Also you should read all appropriate posts to the clj newsgroup
    for several days. Most questions come up at least once every other
    day and people can get annoyed of answering them repeatedly.

    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.
    Use the Subject: of your post to indicate the type of problem you 
    have.
    'Help!' or 'I hate Netscape!' are not nearly as useful to 
    contributors who do not read every post as 'parseInt(09)!=9'.

    Has the same question already been posted that day? - if it has
    wait to see if the answers to that solve your problem.

    Include the script you have been working on (or URL) -
    indicate the problem spots and/or previous attempts. Try to limit
    the length of your post by removing extraneous page elements, but
    avoid removing script unless you are sure it is not an issue, if
    the script is long though, please do not post the full script and
    just provide a link, as a guide more than 500 lines for a post is
    not normally a good idea in any circumstances.  A mention of which
    platforms and browsers in use or giving problems is also necessary. 

    Post in plain-text only. Do not post using HTML. If you have
    to include your script, paste it in to your post in plain-text,
    do not uuencode it or attach it using mime.  There is good reason 
    for this request.  Many newsreaders do not read html or mime, and 
    this limits the number of people who could help you. Before a
    reply, quote only the minimum that needs to be quoted.

    Don't ask, or at least expect, to be emailed individually.
    Some individuals run scams for the purpose of collecting active
    email addresses and many won't risk being victimized. If you have
    circumstances that won't allow you to read clj for the follow-up,
    explain what they are and ask to be CC'ed a copy. You also might
    try one of the sites listed in section 3 to read any follow-ups.

    Don't take flames too seriously. And don't start a thread
    complaining about rude or flippant responses, there is already
    enough noise in clj. Keep a sense of humour while posting and
    reading and everything will be a lot more enjoyable.

    Remember that it is *not* the *job* of posters here to help you. 
    That the majority of regular posters here do so *voluntarily*
    in their free time.  They have good days and bad days just like 
    everyone else.

    clj is a technical group, postings of job adverts and commercial 
    adverts are not welcome - job postings should go to an appropriate
    regional jobs group. Annoucements of products of particular revelance
    to javascript are welcome, but not more often than once per major
    release - then post a short link to your products webpage. 

  2.4 Why was my post not answered?

    This could be for several reasons:

    <a>it was a variation of a frequently asked question and was
        therefore ignored by everyone

    <b>no one knows the answer

    <c>the person with the answer has not seen the post

    <d>it might not be possible to do what you want to do but
        perhaps readers of clj are reluctant to answer your post
        in the negative when they are not convinced that it
        cannot be done.


  2.5 How do I direct someone to this FAQ?

    This document is posted to clj very frequently.
    There should be no reason to direct someone to it. However, if
    someone asks a question answered in this FAQ or in one of the
    resources listed herein, please let them know their question is
    answered in the FAQ and that the FAQ can be found at 
    
    <URL: http://www.jibbering.com/faq/ >

  2.6a What is ECMAScript?

     <URL: http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM >

    ECMAScript is the international standard for javascript. 
    JScript 3.0 and JavaScript 1.2 (available with version 4.
    browsers) are more or less ECMAScript compliant. 
    Note that ECMAScript did not attempt to standardize the 
    document object model.

    The current edition is Edition 3.0, There is some support
    for this edition in JScript 5.0 and JavaScript 1.3,
    JScript 5.5 is fully compliant and JavaScript 1.5 available in
    released versions of Netscape 6 is compliant but for a few missing
    methods. (JS1.5 available in later Mozilla builds is fully
    compliant)

  2.6b What is JScript? 

    JScript is Microsoft's implementation of ECMAScript. 

  2.7 What are object models?

    Object models (OMs) are not part of the javascript language,
    they are provided by the host to allow javascript (or other
    scripting language) to communicate with the host. An object 
    model may allow a javascript to access a file system, or
    control a nuclear power station. The most commonly used
    object models via javascript are provided by Active Server
    Pages, Server Side JavaScript, and the Windows Script Host.
    The most common of all of course is the Document Object 
    Model (DOM) provided by web browsers.

  2.8 What is the Document Object Model?

    This is the collection of objects provided by each browser.
    Basically, any object in the window hierarchy is part of the DOM.
    This means that document.writeln(), for example, is not a
    javascript method but is, in fact, a method provided by the DOM.
    The DOM has been standardised by the w3 consortium however like all
    w3 standards browser support unfortunately is not there yet. Most
    cross-browser coding problems come from slightly different 
    implementations of the DOM in the different browsers.

    <URL: http://www.w3.org/TR/REC-DOM-Level-1/ >

    Level 2 of the DOM standard is already in draft.

  2.9 Internationalisation in javascript.
     
     There is little Internationalisation capability in javascript, 
     the various toString() methods are all implementation dependant,
     but tend to use UK/US settings. ECMAScript Edition 3.0 has introduced 
     some capability including the toLocaleString() method which should 
     create a string based on the hosts locale. In future versions
     of javascript it is expected that there will be much more support.

  2.10 I have a question that is not answered in here

    ... or in any of the resources mentioned here but I'm sure it
    has been answered in clj. Where are the clj archives located?

    <URL: http://groups.google.com/ >
    Maintain a usenet archive going back many years, although
    currently only 6 months are available to search.

 2.11 What does the future hold for ECMAScript?

    The ECMAScript Technical commitee is now working on Edition 4, the
    first implementation of which is likely to be JScript.NET, which has
    been made available in a preview release, and should beta before too
    long, which includes a compiler, allowing you to create standalone
    JScript executables.

    Edition 4.0 of ECMAScript provides new features like typed variables,
    classes, other information can be found at:

    <URL: http://msdn.microsoft.com/voices/scripting07142000.asp >

    or from the newsgroup microsoft.public.net.jscript.general

3.0 Javascript resources
========================

  3.1 What books cover javascript?

    There are rather a lot of javascript books
    available, and if anyone has an example of an up to date
    good javascript book, I'll gladly add it to the faq.

  3.2 What online resources are available?

    Javascript FAQ sites, please check these first:
    <URL: http://www.irt.org/script/faq.htm >
    <URL: http://javascript.faqts.com/ >

    Index of docs online and for download:
    <URL: http://docs.iplanet.com/docs/manuals/javascript.html >

    (D)HTML reference:
    <URL: http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtmlrefs.asp >

    JScript reference and main Microsoft script site:
    <URL http://msdn.microsoft.com/scripting/jscript/doc/jstoc.htm >
    <URL: http://msdn.microsoft.com/scripting/ >

    Archived documentation for MSIE 3.x:
    <URL: http://members.tripod.com/~housten/download/ >

    The official ECMAScript specification:
    <URL: http://www.ecma.ch/ecma1/STAND/ECMA-262.HTM >

    DOM level 1 ECMA script binding:
    <URL: http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html >

    FESI - a free implementation of ECMAScript in Java:
    <URL: http://home.worldcom.ch/~jmlugrin/fesi/index.html >

    Frequently asked questions about source code obfuscation:
    <URL: http://ugweb.cs.ualberta.ca/~thompson/programming/javascript/protect.html >

    Sites discussing Active Server Pages:
    <URL: http://www.15seconds.com/ >
    <URL: http://www.4guysfromrolla.com/ >
    <URL: http://www.aspfaq.com/ >
         
    DHTML source code and tutorials to a high standard:
    <URL: http://www.dansteinman.com/dynduo/ >
    <URL: http://www.w3schools.com/ >
        
    Sites focused on using Scripting to automate Windows:
    <URL: http://www.windows-script.com/ >
    <URL: http://cwashington.netreach.net/ >

    Code for manipulating dates in javascript:
    <URL: http://www.merlyn.demon.co.uk/js-dates.htm >

    Games written in javascript:
    <URL: http://www.javascript-games.org/ >

4.0 Quick Answers
==================

  4.1 How do I protect my javascript code/disable right mouse button?

    In the main you don't, as the language is interpreted, you need
    to deliver the source code, with JScript, there is the Script
    Encoder (see MSDN) but this is nothing more than obfuscation
    in effect, disabling the Right Mouse button, also achieves
    nothing to protect your script in a web browser.

    Your code is likely protected under copyright laws see:
    < URL: http://www.wipo.org/eng/general/copyrght/intro.htm >
    < URL: http://html.about.com/compute/html/msubcopyright.htm >

  4.2 How can I disable the back button in a web browser?

    You can't, the browsers history cannot be modified, you can however
    use location.replace(url) in some browsers to replace the current 
    page in the history.

  4.3 How can I access the client-side filesystem?

    Security means that by default you can't, in a more restricted
    enviroment, there are options, (e.g. live connect to Java in NN, 
    and using FileSystemObject in IE) check http://groups.google.com/
    for previous posts on the subject.

  4.4 How can I see in javascript if a web browser accepts cookies?
      
    Writing a cookie, reading it back and checking if it's the same.

  4.5 How can I protect a webpage in javascript?

    You can't security needs to be done serverside, client side 
    protection does not work.

  4.6 How do I format 6.57634 to 6.58 or 6.5 to 6.50?

    In ECMAScript Ed. 3.0 (JScript 5.5 (but buggy)/JavaScript 1.5)
  num.toFixed(2) 
    or for previous versions:
  Math.round(num*100)/100, (doesn't add trailing zeros.)
    Adding trailing zeros is more complicated to achieve without
    failing for some numbers, the below from
    < http://www.merlyn.demon.co.uk/js-maths.htm#Round > work
    successfully (slightly modified to add the prototype to the
    number object.)

   function Stretch(Q, L, c) { var S = Q
   if (c.length>0) while (S.length=0.0
   var T, S=new String(Math.round(X*Number("1e"+N)))
   if (S.search(/e/)!=-1) { return ''+X }
   with (new String(Stretch(S, M+N, '0')))
    return substring(0, T=(length-N)) + '.' + substring(T) }

   function Sign(X) { return X<0 ? '-' : ''; }
   function StrS(X, M, N) { return Sign(X)+StrU(Math.abs(X), M, N) }

    Number.prototype.toFixed= new Function('n','return StrS(this,1,n)')

 
  4.7 Why does 5 * 1.015 != 5.075?

    Numbers which are finite in Decimal, maybe recurring in
    the Binary system used inside javascript, see 4.6 on how
    to cope with this feature.

  4.8 How do I communicate between frames in a web browser?

    To reference another frame, you simply need to step through the
    frame hierachy, parent is the page the frame is defined in, 
    parent.framename is another frame in the same frameset as the 
    frame you are in. So to access a variable called Moomin in a 
    frame called Snork that is in the same frameset you're in you 
    would use parent.Snork.Moomin, to call the function Snufkin
    in that frame you would use parent.Snork.Snufkin()  .

  4.9 How do I find the size of a browser window?

    Where supported in NN: (>NN4.0)
     var winWidth = window.innerWidth;
     var winHeight = window.innerHeight;
    Where supported in IE: (>IE4.0)
     var winWidth = document.body.clientWidth;
     var winHeight = document.body.clientHeight;

  4.10 How do I check to see if a child window is open, before
  opening another?

    var myWin=null;
    function openWin(aURL) {
     if (!myWin || myWin.closed ) {
      myWin=window.open(aURL,'myWin');
     } else{
      myWin.location=aURL;
      myWin.focus();
     }
    }

  4.11 Why does framename.print() not print the right frame in IE?

    IE prints the frame that has focus when you call the print method:

    frameref.focus();frameref.print();  

  4.12 Why does parseInt(09) give an error?

    parseInt decides what base the number is by looking at the
    number, by convention it assumes any number beginning with 0 is
    Octal, and any number beginning with 0x Hexadecimal, to force
    use of base 10 add a second parameter parseInt(09,10)

  4.13 How do I get the value of a SELECT box in NN?

    el=document.forms['formname'].elements['elementname'];
    value=el[el.selectedIndex].value;
   
  4.14 How do I close a window and why does it not work on
  the first one?

    windowref.close(); windowref is window, or self, top, parent, or a
    reference obtained when opening the window, you can only close
    windows opened by script, no others.

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

    At its simplest in current DOM2 (with innerHTML extension) 
    (IE5+ NS6 ) then:

    HTML: < div id="aID">Some Content</div>
    Script:
    document.getElementById("aID").innerHTML="Some <em>new</em> Content";
 
    works, it is possible though in IE 4+, NS 4+, code
    like below achieves it, but not without many problems in more
    complicated situations than described, be careful:

    HTML:<div ID=aID><ilayer name=aID>Some Content</ilayer></div>
    Script:
    DynWrite('aID',"Some <em>new</em> Content")

    With the below code also in the page:

    DocDom = (document.getElementById?true:false);
    DocLay = (document.layers?true:false);
    DocAll = (document.all?true:false);
    DocStr=''
    if (DocLay) DocStr="return document.layers[id]"
    if (DocAll) DocStr="return document.all[id]"
    if (DocDom) DocStr="return document.getElementById(id)"
    GetRef=new Function("id", DocStr)
    if (DocStr=='') { DynWrite=new Function("return false") } else {
     if (DocAll || DocDom) {
      DynWrite=new Function("id", "S", "GetRef(id).innerHTML=S; return true")
     }
     if (DocLay) DynWrite=new Function("id", "S", "var x=GetRef(id).document;"+
      "x.open('text/html'); x.write(S); x.close(); return true")
    }

5.0 Comments
=============

   There have been many contributors to this FAQ in its history,
   thanks to them all for a list see:
   <URL: http://www.jibbering.com/faq/contributors.html >

   If you have any suggestions for the FAQ, or further questions
   that you feel should be answered here, please e-mail me at the
   address below. 

=========================

 FAQ Maintained by Jim Ley - Jim@Jibbering.com