Compare Revisions
Last modification
- Rev 25 2012-12-19 21:30:47
- Author: PointedEars
- Log message:
cljs: Moved sections into XML includes
/trunk/cljs/sections/server.xml |
File deleted |
\ No newline at end of file
|
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/meta.xml |
=================================================================== |
--- cljs/sections/meta.xml (revision 25) |
+++ cljs/sections/meta.xml (nonexistent) |
@@ -1,150 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Meta-FAQ meta-questions" ID="meta" NUMID="1"> |
- <P> |
- This is the <EM>comp.lang.javascript</EM> meta-FAQ, <VER/>. The latest |
- version is available at <URL>http://jibbering.com/faq/</URL> in HTML form. |
- </P> |
- <P> |
- Each day, one section of the FAQ is posted for review and questions, |
- and as a reminder that the FAQ is available. |
- </P> |
- <P> |
- For additional explanation and detail relating to some aspects |
- of the FAQ, please see the |
- <URL LINKTEXT="FAQ Notes">notes/</URL>. |
- It has been provided separately to avoid increasing the size of |
- the FAQ to a point where it would be unreasonable to post it to |
- the group. |
- </P> |
- <P> |
- Code examples in this FAQ use <URL LINKTEXT="JSDoc Toolkit" |
- >http://jsdoctoolkit.org/</URL> comments. |
- </P> |
- |
- <CONTENT TITLE="Which newsgroups deal with javascript?" ID="newsgroups" NUMID="2_1"> |
- <P> |
- The official Big 8 Usenet newsgroup dealing with javascript is |
- <NEWSGROUP>comp.lang.javascript</NEWSGROUP>. |
- Some "language" hierarchies also have *.comp.lang.javascript groups. |
- </P> |
- <P> |
- c.l.js is an unmoderated newsgroup. |
- </P> |
- </CONTENT> |
- |
- <CONTENT TITLE="What questions are on-topic for comp.lang.javascript?" ID="appropriateQuestions" NUMID="2_2"> |
- <P> |
- The comp.lang.javascript newsgroup deals with ECMAScript |
- languages, so any questions about JavaScript or JScript are |
- welcome. However, the majority of questions sent to this group |
- relates to javascript in a web browser. If you are experiencing |
- issues with a particular browser, or the host is not a browser |
- at all, please make this information clear. |
- </P> |
- <P> |
- 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 c.l.js (as Java and |
- javascript are distinct programming languages with only |
- superficial similarities due to sharing a C-like syntax and |
- some of the characters in their names). |
- </P> |
- <P> |
- Questions dealing with other scripting languages, such as |
- VBScript, PerlScript or CGI scripting are also off-topic, |
- as are HTML-only or CSS-only questions. |
- </P> |
- <!-- |
- <P> |
- Questions about the design of various javascript libraries are |
- appropriate; questions on how to <EM>use</EM> such libraries |
- are not. Check <URL LINKTEXT="c.l.js FAQ Resources" |
- >http://jibbering.comindex.html#libraryResources</URL> or search the web. |
- </P> |
- --> |
- <P> |
- Questions that are specific to Microsoft's JScript may also |
- be appropriately asked at: |
- <NEWSGROUP>microsoft.public.scripting.jscript</NEWSGROUP> |
- </P> |
- <P> |
- The comp.lang.javascript newsgroup charter is included in |
- <URL>faq_notes/cljs_charter.html</URL>. |
- </P> |
- </CONTENT> |
- |
- <CONTENT TITLE="What should I do before posting to comp.lang.javascript?" ID="posting" NUMID="2_3"> |
- <P> |
- Before posting to c.l.js, you should read this document. |
- You should also check the <URL LINKTEXT="Resources section">#onlineResources</URL>. |
- </P> |
- <LIST TYPE="UL" TITLE="How to Ask a Question" ID="ask"> |
- <LI>State your question clearly and concisely.</LI> |
- <LI>Use the Subject: line to show the type of problem you have but |
- include the question in the body as well.</LI> |
- <LI>For a more detailed explanation of formatting, see |
- "<URL LINKTEXT="Posting Questions and Replies to comp.lang.javascript">notes/posting/</URL>".</LI> |
- </LIST> |
- |
- <LIST TYPE="UL" TITLE="Replying" ID="reply"> |
- <LI>Quote only relevant parts of earlier messages, and add your |
- comments below each quoted section |
- (<URL LINKTEXT="FYI28/RFC1855">http://www.ietf.org/rfc/rfc1855.txt</URL>).</LI> |
- <LI>Link to specific sections of the FAQ that are relevant.</LI> |
- <LI>Avoid being unnecessarily rude, but do not complain about other rude posts.</LI> |
- <LI>Don't quote signatures.</LI> |
- </LIST> |
- |
- <LIST TYPE="UL" TITLE="Posting Code" ID="postCode"> |
- <LI> |
- Remove everything that does not contribute to the problem (images, |
- markup, other scripts, etc). |
- </LI> |
- <LI>Validate the HTML and CSS <URL>http://validator.w3.org/</URL>, |
- <URL>http://jigsaw.w3.org/css-validator/</URL>.</LI> |
- <LI>Make sure the code is executable as transmitted.</LI> |
- <LI>Format lines to 72 characters; indent with 2-4 spaces (not tabs).</LI> |
- <LI>State what you expect the code to do.</LI> |
- <LI>Mention the platforms, browsers, and versions.</LI> |
- <LI>See also the <URL LINKTEXT="FAQ section on debugging">#debugging</URL>.</LI> |
- <LI>Post in plain-text only. Do not encode it. Do not attach files.</LI> |
- <LI>If the code is more than about 100 lines, provide a URL in addition.</LI> |
- <LI>Do not multi-post; cross-post if necessary |
- (<URL LINKTEXT="Wikipedia description">http://en.wikipedia.org/wiki/Cross-post</URL>).</LI> |
- </LIST> |
- <LIST TYPE="UL" TITLE="What Not to Post" ID="doNotPost"> |
- <LI>Do not post job postings. Job postings should go to |
- an appropriate regional jobs group.</LI> |
- <LI>Do not post copyright material without permission |
- from the copyright holder.</LI> |
- </LIST> |
- <P> |
- Relevant announcements are welcome, but no more often than once |
- per major release, as a short link to the product's webpage. |
- </P> |
- </CONTENT> |
- |
- <CONTENT TITLE="Why was my post not answered?" ID="noAnswer" NUMID="2_4"> |
- <P>This could be for several reasons:</P> |
- <UL> |
- <LI>It was a variation of a frequently asked question and was |
- therefore ignored by everyone.</LI> |
- <LI>Nobody knows the answer.</LI> |
- <LI>The person with the answer has not seen the post.</LI> |
- <LI>It might not be possible to do what you want to do but perhaps |
- readers of c.l.js are reluctant to answer your post in the negative |
- when they are not convinced that it cannot be done.</LI> |
- <LI>The question was not asked clearly enough, or did not included |
- enough information to be answered.</LI> |
- <LI>The questioner did not realise the need to read the group, for a |
- few days, to see the answers posted there.</LI> |
- <LI>You ignored the <URL LINKTEXT="section on posting">#posting</URL></LI> |
- </UL> |
- |
- <p>If it is not one of these, then after a few days consider |
- reposting after checking |
- <URL>http://groups.google.com/group/comp.lang.javascript/topics</URL> |
- for replies. Make sure the post is phrased well, and everything |
- needed to answer is correct, and the subject is appropriate.</p> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/meta.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/overview.xml |
=================================================================== |
--- cljs/sections/overview.xml (revision 25) |
+++ cljs/sections/overview.xml (nonexistent) |
@@ -1,109 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Language Overview" ID="tips" NUMID="2"> |
- <CONTENT TITLE="What is ECMAScript?" ID="ecma" NUMID="2_6"> |
- <P> |
- <URL LINKTEXT="ECMA-262">http://www.ecma-international.org/publications/standards/Ecma-262.htm</URL> |
- is the international standard that current language implementations |
- (JavaScript™, JScript etc.) are based on. |
- </P> |
- <P> |
- <URL LINKTEXT="ECMA-262">http://www.ecma-international.org/publications/standards/Ecma-262.htm</URL> |
- defines the language Syntax, Types, Keywords, Operators, and built-in |
- objects. The ECMAScript specification is the reference to determine the |
- expected behavior of a program. ECMAScript does not define any host |
- objects, such as <ICODE>document</ICODE>, <ICODE>window</ICODE>, or |
- <ICODE>ActiveXObject</ICODE>. |
- </P> |
- <P> |
- ECMA-327 defines the Compact Profile of ECMAScript by |
- describing the features from ECMA 262 that may be omitted in some |
- resource-constrained environments. |
- <URL>http://www.ecma-international.org/publications/standards/Ecma-327.htm</URL> |
- </P> |
- <P> |
- The most widely supported edition of ECMA-262 is the 3rd edition (1999). |
- There is fair support for this edition in JScript 5.5+ (buggy) and good |
- support JavaScript 1.5. |
- </P> |
- <P> |
- The term "javascript" is used as a common name for all dialects of ECMAScript. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="What is JScript?" ID="jScript" NUMID="2_7"> |
- <P> |
- JScript is Microsoft's implementation of ECMAScript. |
- </P> |
- <P> |
- Questions that are specific to Microsoft's JScript may also |
- be appropriately asked at: |
- <NEWSGROUP>microsoft.public.scripting.jscript</NEWSGROUP>. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="What is the Document Object Model (DOM)?" ID="dom" NUMID="2_9"> |
- <P> |
- The <DFN>Document Object Model</DFN> (DOM) is a interface-based model for <ICODE>Document</ICODE> |
- objects. The DOM allows scripts to dynamically access and update a |
- document's content, style, and event handlers. |
- </P> |
- <P> |
- The DOM is <EM>not</EM> part of the ECMAScript programming language. |
- </P> |
- <P> |
- Official DOM standards are defined by the World Wide Web Consortium. |
- Scriptable browsers also have <DFN>proprietary</DFN> DOM features (<URL |
- LINKTEXT="MSDN">http://msdn.microsoft.com/en-us/library/ms533050(VS.85).aspx</URL>, <URL |
- LINKTEXT="MDC">https://developer.mozilla.org/en/DOM_Client_Object_Cross-Reference</URL>), |
- such as <ICODE>document.writeln()</ICODE>. |
- </P> |
- <P> |
- Also see the section on <URL LINKTEXT="DOM and Forms">#domRef</URL>. |
- </P> |
- <MOREINFO> |
- <URL LINKTEXT="c.l.js DOM Resources">#onlineResources</URL> |
- <URL LINKTEXT="W3C DOM FAQ">http://www.w3.org/DOM/faq.html</URL> |
- <URL LINKTEXT="W3C DOM ">http://www.w3.org/DOM/</URL> |
- <URL LINKTEXT="MDC: What is the DOM?">https://developer.mozilla.org/en/Gecko_DOM_Reference/Introduction#What_is_the_DOM.3F</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="Internationalisation and Localisation in javascript" ID="localization" NUMID="2_10"> |
- <P> |
- <DFN>Internationalisation</DFN> means using one form which is everywhere both |
- acceptable and understood. Any international standard not supported by |
- default can be coded for. |
- </P> |
- <P> |
- For example, there is an International Standard for numeric Gregorian |
- date format; but none for decimal and thousands separators. |
- </P> |
- <P> |
- <DFN>Localisation</DFN> is the process of adapting software for a specific region |
- or language by adding locale-specific components and translating text. It |
- cannot work well in general, because it requires a knowledge of all |
- preferences and the ability to choose the right one, in an environment |
- where many systems are inappropriately set anyway. |
- </P> |
- <P> |
- ECMAScript has a few <DFN>localisation</DFN> features. The various |
- <ICODE>toString()</ICODE> methods are all implementation dependent, |
- but tend to use either UK or US settings (not necessarily correctly). |
- ECMAScript Ed. 3 introduced some capabilities, including the |
- <ICODE>toLocaleString()</ICODE>method which should create a string |
- based on the host's locale. |
- </P> |
- <P> |
- ECMAScript 5th Edition introduces limited ISO 8601 capabilities with |
- <ICODE>Date.prototype.toISOString()</ICODE> and new behavior for <ICODE>Date.parse()</ICODE>. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="What does the future hold for ECMAScript?" ID="futureEcmaScript" NUMID="2_12"> |
- <P> |
- The 5th edition of ECMAScript was approved on 2009-12-04. There is some |
- support in implementations released before approval date (JScript 5.8, |
- JavaScript 1.8, JavaScriptCore). |
- http://www.ecma-international.org/publications/standards/Ecma-262.htm |
- </P> |
- <MOREINFO> |
- <URL>http://www.ecma-international.org/publications/standards/Ecma-262.htm</URL> |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/overview.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/donts.xml |
=================================================================== |
--- cljs/sections/donts.xml (revision 25) |
+++ cljs/sections/donts.xml (nonexistent) |
@@ -1,175 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Things not to attempt in a browser" ID="doNotTry"> |
- <CONTENT TITLE="How do I detect Opera/Safari/IE?" ID="detectBrowser" NUMID="4_26"> |
- <P> |
-The short answer: <EM>Don't do that</EM>. |
- </P> |
- <P> |
-The <ICODE>navigator</ICODE> <DFN>host object</DFN> contains properties which |
-may identify the browser and version. These properties are historically |
-inaccurate. Some browsers allow the user to set <ICODE>navigator.userAgent</ICODE> to any value. For |
-example, Firefox, (type <ICODE>about:config</ICODE> and search <ICODE>useragent</ICODE> |
-or Safari, <ICODE>Develop > User Agent > Other...</ICODE>, IE, via Registry. |
- </P> |
- <P> |
-Other browsers, such as Opera, provide a list of user agents |
-for the user to select from. There are also at least 25 other |
-javascript capable browsers, with multiple versions, each |
-with their own string. |
- </P> |
- <P> |
-Browser detection is unreliable, at best. It usually causes |
-forward-compatibility and maintenance problems. It is unrelated to the |
-problem or incompatiblity it is trying to solve and obscures the |
-problems it is used for, where it is used. |
- </P> |
- <P> |
-Object detection is checking that the object in question exists. |
-<URL LINKTEXT="Capability detection" |
->http://dev.opera.com/articles/view/using-capability-detection/</URL |
- > goes one step further to actually test the object, |
-method, or property, to see if behaves in the desired manner. |
- </P> |
- <P> |
-Feature Test Example: |
- </P> |
- <CODE> |
-/** |
- * Returns the element/object the user targeted. |
- * If neither DOM nor IE event model is supported, returns undefined. |
- * @throws TypeError if the event is not an object. |
- */ |
-function getEventTarget(e) { |
- e = e || window.event; |
- // First check for the existence of standard "target" property. |
- return e.target || e.srcElement; |
-}</CODE> |
-<MOREINFO> |
-<URL>notes/detect-browser/</URL> |
-<URL>http://dev.opera.com/articles/view/using-capability-detection/</URL> |
-<URL>http://developer.apple.com/internet/webcontent/objectdetection.html</URL> |
-<URL>http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43</URL> |
-</MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How can I prevent access to a web page by using javascript?" |
- ID="preventAccess" NUMID="4_5"> |
- <P> |
-In practice you can't. While you could create a suitable |
-encryption system with a password in the page, the level of |
-support you need to do this means it's always simpler to do it |
-server-side. Anything that "protects" a page |
-other than the current one is definitely flawed. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="How do I protect my javascript code?" ID="hideSource" NUMID="4_1"> |
- <P> |
-With clientside javascript you can't as your code is distributed |
-in source form and is easily readable. With JScript, there is the |
-Script Encoder (see MSDN), but this is nothing more than obfuscation. |
-Attempting to disable the context menu does nothing to |
-protect your script in a Web browser. |
- </P> |
- <MOREINFO> |
- Your code is likely protected under copyright laws. See: |
- <URL>http://www.wipo.int/about-ip/en/copyright.html</URL> |
- <URL>http://webdesign.about.com/od/copyright/Copyright_Issues_on_the_Web_Intellectual_Property.htm</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I suppress a context menu (right-click menu)?" |
- ID="disableRightClick" NUMID="4_27"> |
- <P> |
-A context menu, often triggered by right-click, can be requested by the |
-user in a few ways. For example, on windows, shift + F10 and on macs, |
-click-and-hold. Other input devices exist and mouse buttons can be |
-configured, making the term "right click" a misnomer, in context. |
-</P> |
-<P> |
-In browsers that allow it, a script can suppress the context menu by |
-returning false from an object's <ICODE>oncontextmenu</ICODE> event handler. |
-</P> |
-<CODE> |
-document.oncontextmenu = function() { |
- return false; |
-}; |
-</CODE> |
-<P> |
-Some browsers lack context menus (e.g. iphone). Browsers that have |
-context menus do not always have a scriptable event for them. Some |
-browsers can be configured to disallow scripts from detecting context |
-menu events (IE, Opera); others may fire the event but be configured to |
-disallow scripts from suppressing the context menu (Firefox,Seamonkey). |
-</P> |
-<P> |
-Even when the context menu has been suppressed, it will still be |
-possible to view/save the source code and to save images. |
-</P> |
-<MOREINFO> |
-<URL>http://en.wikipedia.org/wiki/Context_menu</URL> |
-<URL>http://kb.mozillazine.org/Ui.click_hold_context_menus</URL> |
-<URL>http://support.microsoft.com/kb/823057</URL> |
-<URL>http://stackoverflow.com/questions/1870880/opera-custom-context-menu-picking-up-the-right-click/1902730#1902730</URL> |
-<URL>http://support.mozilla.com/en-US/kb/Javascript#Advanced_JavaScript_settings</URL> |
-<URL>http://msdn.microsoft.com/en-us/library/ms536914%28VS.85%29.aspx</URL> |
-</MOREINFO> |
-</CONTENT> |
- <CONTENT TITLE="How can I access the client-side filesystem?" ID="readFile" NUMID="4_3"> |
- <P> |
-Security means that by default you can't. In a more restricted |
-environment, there are options. For example, using LiveConnect to |
-connect to Java with Netscape, and using the FileSystemObject in |
-IE. Check <URL LINKTEXT="Google Groups archives">http://groups.google.com/group/comp.lang.javascript/topics</URL> |
-for previous posts on the subject. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/z9ty6h50%28VS.85%29.aspx</URL> |
- <URL>http://www.javaworld.com/javaworld/jw-10-1998/jw-10-apptowin32.html</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="I have <a href="javascript:somefunction()"> what ... ?" |
- ID="javascriptURI" NUMID="4_24"> |
- <P> |
-Whatever the rest of your question, this is generally a very bad idea. |
-The <ICODE>javascript:</ICODE> pseudo protocol was designed to replace the |
-current document with the value that is returned from the expression. |
-For example: |
- </P> |
- <CODE> |
- <a href="javascript:'<h1>' + document.lastModified + '</h1>'">lastModified</a> |
-</CODE> |
- <P> |
-will result in replacing the current document with the value |
-returned from <ICODE>document.lastModified</ICODE>, wrapped in an <ICODE><h1></ICODE> |
-tag. |
- </P> |
- <P> |
-When the expression used evaluates to an <ICODE>undefined</ICODE> value |
-(as some function calls do), the contents of the current page are not |
-replaced. Regardless, some browsers (notably IE6) interpret this as |
-navigation and will enter into a 'navigation' state where GIF |
-animations and plugins (such as movies) will stop and navigational |
-features such as <ICODE>META</ICODE> refresh, assignment to <ICODE>location.href</ICODE>, and image |
-swaps fail. |
- </P> |
- <P> |
-It is also possible for IE to be configured such that it supports |
-javascript but not the <ICODE>javascript:</ICODE> protocol. This results |
-in the user seeing a protocol error for <ICODE>javascript:</ICODE> URIs. |
- </P> |
- <P> |
-The <ICODE>javascript:</ICODE> pseudo protocol creates accessibility and |
-usability problems. It provides no fallback for when the script is not |
-supported. |
- </P> |
- <P> |
-Instead, use |
-<ICODE><a href="something.html" onclick="somefunction();return false"></ICODE> |
-where <ICODE>something.html</ICODE> is a meaningful alternative. Alternatively, |
-attach the <ICODE>click</ICODE> callback using an event registry. |
- </P> |
- <MOREINFO> |
- <URL>example/jsuri/</URL> |
- <URL LINKTEXT="Set/Navigate to a Location">http://groups.google.com/group/comp.lang.javascript/msg/f665cfca3b619692</URL> |
- <URL LINKTEXT="Top Ten Web-Design Mistakes of 2002">http://www.useit.com/alertbox/20021223.html</URL> |
- </MOREINFO> |
- </CONTENT> |
- </CONTENT> |
\ No newline at end of file |
/cljs/sections/donts.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/functions.xml |
=================================================================== |
--- cljs/sections/functions.xml (revision 25) |
+++ cljs/sections/functions.xml (nonexistent) |
@@ -1,81 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Functions" ID="functions"> |
- <CONTENT TITLE="What is (function(){ /*...*/ })() ?" ID="scope"> |
- <P> |
- This is an anonymous <DFN>FunctionExpression</DFN> that is called |
- immediately after creation. |
- </P> |
- <P> |
- Variables declared inside a function are not accessible from |
- outside the function. This can be useful, for example, to hide |
- implementation details or to avoid polluting the global scope. |
- </P> |
- <MOREINFO> |
- <URL>http://yura.thinkweb2.com/named-function-expressions/</URL> |
- <URL>notes/closures/</URL> |
- <URL>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses</URL> |
- </MOREINFO> |
- </CONTENT> |
- |
- <CONTENT TITLE="What is a function statement?" ID="functionStatement"> |
- <P> |
- The term <DFN>function statement</DFN> has been widely and wrongly used to |
- describe a <ICODE>FunctionDeclaration</ICODE>. This is misleading because in ECMAScript, |
- a <ICODE>FunctionDeclaration</ICODE> is not a <DFN>Statement</DFN>; there are places in a program |
- where a <DFN>Statement</DFN> is permitted but a <ICODE>FunctionDeclaration</ICODE> is not. To add |
- to this confusion, some implementations, notably Mozillas', provide a |
- syntax extension called <DFN>function statement</DFN>. This is allowed under |
- section 16 of ECMA-262, Editions 3 and 5. |
- </P> |
- <P> |
- Example of nonstandard <DFN>function statement</DFN>: |
- </P> |
- <CODE> |
-// Nonstandard syntax, found in GMail source code. DO NOT USE. |
-try { |
- // FunctionDeclaration not allowed in Block. |
- function Fze(b,a){return b.unselectable=a} |
- /*...*/ |
-} catch(e) { _DumpException(e) } |
- </CODE> |
- <P> |
- Code that uses <DFN>function statement</DFN> has three known interpretations. Some |
- implementations process <ICODE>Fze</ICODE> as a <DFN>Statement</DFN>, in order. Others, including |
- JScript, evaluate <ICODE>Fze</ICODE> upon entering the execution context that it |
- appears in. Yet others, notably DMDScript and default configuration of BESEN, |
- throw a <ICODE>SyntaxError</ICODE>. |
- </P> |
- <P> |
- For consistent behavior across implementations, <EM>do not use function |
- statement</EM>; use either <ICODE>FunctionExpression</ICODE> or <ICODE>FunctionDeclaration</ICODE> instead. |
- </P> |
- <P> |
- Example of <ICODE>FunctionExpression</ICODE> (valid): |
- </P> |
- <CODE> |
-var Fze; |
-try { |
- Fze = function(b,a){return b.unselectable=a}; |
- /*...*/ |
-} catch(e) { _DumpException(e) } |
- </CODE> |
- Example of <ICODE>FunctionDeclaration</ICODE> (valid): |
- <CODE> |
-// Program code |
-function aa(b,a){return b.unselectable=a} |
- </CODE> |
-<!-- |
-Notable examples of the misuse of the term "function statement" |
-can be seen in David Flanagan's "JavaScript: The Definitive Guide", |
-Douglas Crockford's "JavaScript: The Good Parts", MDC documentation, |
-JSLint error messages. |
---> |
- <MOREINFO> |
- <URL>example/functionStatement.html</URL> |
- <URL>https://mail.mozilla.org/pipermail/es-discuss/2008-February/005314.html</URL> |
- <URL>http://groups.google.com/group/comp.lang.javascript/msg/aa9a32d0c6ae0342</URL> |
- <URL>http://groups.google.com/group/comp.lang.javascript/msg/3987eac87ad27966</URL> |
- <URL>http://nanto.asablo.jp/blog/2005/12/10/172622</URL> (Article in Japanese) |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/functions.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/objects.xml |
=================================================================== |
--- cljs/sections/objects.xml (revision 25) |
+++ cljs/sections/objects.xml (nonexistent) |
@@ -1,136 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Objects" ID="objects"> |
- <CONTENT TITLE="What is a native object?" ID="nativeObject"> |
- <P> |
- A <DFN>native object</DFN> is any object whose semantics are fully defined by |
- ECMA-262. |
- </P> |
- <P> |
- Some <DFN>native objects</DFN> are <DFN>built-in</DFN>; others, such as <DFN>user-defined</DFN> objects, |
- may be constructed during the execution of an ECMAScript program. |
- </P> |
- <P> |
- Example: |
- </P> |
- <CODE> |
-// Native built-in objects: |
-var m = Math, // Built-in Math object. |
- slice = Array.prototype.slice, // Built-in native method. |
- o = {}, // Native user-defined object. |
- f = function(){}, // Native user-defined function. |
- d = new Date(), |
- a = [], |
- e = new Error("My Message."); |
- </CODE> |
- See also: |
- <MOREINFO> |
- <URL>http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="What is a built-in object?" ID="builtInObject"> |
- <P> |
- A <DFN>built-in</DFN> object is any object supplied by an ECMAScript |
- implementation, independent of the host environment, that is present |
- at the start of the execution of an ECMAScript program. |
- </P> |
- <P> |
- ECMA-262 3rd Edition defines the following <DFN>built-in</DFN> objects: |
- </P> |
- <LIST TYPE="DL" ID="builtInsList"> |
- <DT>Objects</DT> |
- <DD><EM>global</EM>, Math</DD> |
- |
- <DT>Constructors</DT> |
- <DD>Object, Function, Array, String, Boolean, Number, Date, RegExp</DD> |
- |
- <DT>Errors</DT> |
- <DD>Error, Date, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError</DD> |
- |
- <DT>Functions</DT> |
- <DD>eval, parseInt, parseFloat, isNaN, isFinite, decodeURI, |
- decodeURIComponent, encodeURI, encodeURIComponent</DD> |
- </LIST> |
- <P> |
- ECMA-262 Edition 5 defines also the built-in object <ICODE>JSON</ICODE>. |
- </P> |
- <P> |
- Nonstandard <DFN>built-in</DFN> objects may include <ICODE>RuntimeObject</ICODE>, |
- <ICODE>String.prototype.link</ICODE>, <ICODE>CollectGarbage</ICODE>, and more. |
- </P> |
- </CONTENT> |
- |
- <CONTENT TITLE="What is a host object?" ID="hostObject" NUMID="2_8"> |
- <P> |
- A <DFN>host object</DFN> is any object supplied by the host environment to |
- complete the execution environment of ECMAScript. |
- </P> |
- <P> |
- A <DFN>host object</DFN> is not part of the ECMAScript implementation, but is |
- exposed to the ECMAScript implementation. |
- </P> |
- <P> |
- A <DFN>host object</DFN> may be implemented as a native ECMAScript object, however |
- this is not required. For example, Internet Explorer implements many |
- scriptable DOM objects as ActiveX Objects, often resulting in unexpected errors. |
- </P> |
- <P> |
- Availability and behavior of a host object depends on the host environment. |
- </P> |
- <P> |
- For example, in a browser, <ICODE>XMLHttpRequest</ICODE> might be available, with or |
- without standard or proprietary features or events. Windows Script Host object model |
- has the <ICODE>WScript</ICODE> object available. |
- </P> |
- <P> |
- For information on a particular host object, consult the pertinent |
- documentation available for the implementation(s). For web browsers, |
- this usually includes the w3c specifications as well as documentation |
- for that browser. |
- See also: |
- </P> |
- |
- <MOREINFO> |
- <URL>notes/code-guidelines/#hostObjects</URL> |
- <URL>http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="When should I use eval?" ID="eval" NUMID="4_40"> |
- <P> |
-The <ICODE>eval</ICODE> function should <EM>only</EM> be used when it is necessary to |
-evaluate a string supplied or composed at run-time; the string |
-can be anything from a simple (but unpredictable) expression such |
-as <ICODE>"12 * 2.54"</ICODE> to a substantial piece of javascript code. |
-</P> |
-<P> |
-When <ICODE>eval( '{"key" : 42}' )</ICODE> is called, <ICODE>{</ICODE> is interpreted as a block of |
-code instead of an object literal. Hence, the Grouping Operator (parentheses) |
-is used to force <ICODE>eval</ICODE> to interpret the JSON as an object literal: |
-<ICODE>eval( '({"key" : 42})' );</ICODE>. |
- </P> |
- <MOREINFO> |
- <URL>http://json.org/</URL> |
- <URL LINKTEXT="How do I access a property of an object using a string?" |
- >#propertyAccessAgain</URL> |
- <URL>notes/square-brackets/</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I access a property of an object using a string?" ID="propertyAccessAgain" NUMID="4_39"> |
- <P> |
- There are two ways to access properties: dot notation and square bracket |
- notation. What you are looking for is the square bracket notation in |
- which the dot, and the identifier to its right, are replaced with a set |
- of square brackets containing a string. The value of the string matches |
- the identifier. For example:- |
- </P> |
- <CODE> |
-//dot notation |
-var bodyElement = document.body; |
- |
-//square bracket notation, using an expression |
-var bodyElement = document["bo"+"dy"]; |
- </CODE> |
- <MOREINFO> |
- <URL>notes/square-brackets/</URL> |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/objects.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/strings.xml |
=================================================================== |
--- cljs/sections/strings.xml (revision 25) |
+++ cljs/sections/strings.xml (nonexistent) |
@@ -1,33 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Strings and RegExp" ID="strings"> |
- <CONTENT TITLE="How do I trim whitespace?" ID="trimString" NUMID="4_16"> |
- <P> |
- ECMAScript 5 defines <ICODE>String.prototype.trim</ICODE>. Where not supported, |
- it can be added as a function that uses a <DFN>regular expression</DFN>: |
- </P> |
- <CODE> |
-if(!String.prototype.trim) { |
- String.prototype.trim = function() { |
- return String(this).replace(/^\s+|\s+$/g, ""); |
- }; |
-} |
- </CODE> |
- <P> |
- Implementations are inconsistent with <ICODE>\s</ICODE>. For example, |
- some implementations, notably JScript 5.8 and Safari 2, do not match <ICODE>\xA0</ICODE> |
- (no-break space), among others.</P> |
- <P> |
- A more consistent approach would be to create a character class |
- that defines the characters to trim. |
- </P> |
- <MOREINFO> |
- <URL>https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp</URL> |
- <URL>http://thinkweb2.com/projects/prototype/whitespace-deviations/</URL> |
- <URL>https://developer.mozilla.org/en/Firefox_3.1_for_developers</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/regexp.htm</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/6wzad2b2%28VS.85%29.aspx</URL> |
- <URL>http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/c7010139217600c3/31092c5eb99625d0?#31092c5eb99625d0</URL> |
- <URL>http://unicode.org/Public/UNIDATA/PropList.txt</URL> |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/strings.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/windows.xml |
=================================================================== |
--- cljs/sections/windows.xml (revision 25) |
+++ cljs/sections/windows.xml (nonexistent) |
@@ -1,483 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Windows and Frames" ID="windows"> |
- <P> |
- The <ICODE>window</ICODE> object (also referred to by <ICODE>self</ICODE>) is "DOM Level 0". |
- No formal standard for it exists. |
- </P> |
- <CONTENT TITLE="How can I disable the back button in a web browser?" ID="disableBackButton" NUMID="4_2"> |
- <P> |
- You can't. The browser's history cannot be modified. However, you |
- can use <ICODE>self.location.replace(url);</ICODE> in some browsers to replace |
- the current page in the history. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms536712%28VS.85%29.aspx</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/location.htm#1194240</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I access a frame's content?" |
- ID="frameRef" NUMID="4_8"> |
- <P> |
- To reference another frame on the <EM>same domain</EM>: |
- </P> |
- <P> |
- The <DFN>content window</DFN> of a <ICODE>FRAME</ICODE> or <ICODE>IFRAME</ICODE> can be |
- accessed by the <ICODE>frames</ICODE> collection. |
- </P> |
- <P> |
- Example: |
- </P> |
- <CODE> |
-var fwin; |
-fwin = self.frames[0]; // or: |
-fwin = self.frames["iframeName"]; |
- </CODE> |
- <P>or, from the <ICODE>IFRAME</ICODE> or <ICODE>FRAME</ICODE> element:</P> |
- <CODE> |
-var iframeEl = document.getElementById("myFrame"); |
-var fwin = iframeEl.contentWindow; // Nonstandard, but widely supported. |
-var fdoc = iframeEl.contentDocument; // DOM2 HTML Standard. |
- </CODE> |
- <P> |
- A global identifier <ICODE>moomin</ICODE> in the the iframe's <DFN>content window</DFN> |
- is accessed as <ICODE>fwin.moomin</ICODE>. |
- </P> |
- <P> |
- To communicate between frames on <EM>different</EM> domains: |
- </P> |
- <P> |
- Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use |
- <ICODE>window.postMessage( message[, port], otherDomain);</ICODE>. |
- </P> |
- <P> |
- Example: |
- <URL>http://jibbering.com/faq/example/postMessage.html</URL> |
- </P> |
- <P> |
- Where <ICODE>window.postMessage</ICODE> is not supported, the <ICODE>window.name</ICODE> property |
- can be set on the other window, which can poll for updates to that |
- property using <ICODE>setInterval(checkWinName, 100);</ICODE> where <ICODE>checkWinName</ICODE> |
- is a function that polls to check the value of |
- <ICODE>self.name</ICODE>. |
- </P> |
- <MOREINFO> |
- <URL>http://en.wikipedia.org/wiki/Same_origin_policy</URL> |
- <URL>http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html</URL> |
- <URL>https://developer.mozilla.org/en/DOM/window.postMessage</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I find the size of the window?" ID="getWindowSize" |
- NUMID="4_9"> |
- <P> |
- Here is a detailed explanation of a cross-browser strategy to |
- find the dimensions of the viewport, excepting all chrome |
- (excludes scrollbars, etc). |
- </P> |
- <P> |
- We can consider various properties: |
- </P> |
- <CODE> |
-window.innerWidth |
-document.clientWidth |
-document.documentElement.clientWidth |
-document.body.clientWidth |
- </CODE> |
- <P> |
- Of the browsers that have an <ICODE>innerWidth</ICODE> property, most |
- include scrollbar dimensions. Some versions of KHTML browsers |
- (including Safari 2) do <EM>not</EM> include scrollbar width. |
- </P> |
- |
- <P> |
- The <ICODE>window.inner*</ICODE> properties are unreliable and not |
- useful here. We don't want scrollbar dimensions included. |
- </P> |
-<CODE> document.clientWidth</CODE> |
- <P> |
- Certain versions of KHTML, including Safari 2, have |
- <ICODE>document.clientHeight</ICODE> and <ICODE>document.clientWidth</ICODE> |
- properties. Where supported, these rare properties accurately |
- return the height and width of the viewport, without including |
- scrollbar dimensions. |
- </P> |
- <CODE> |
-document.documentElement.clientWidth |
-document.body.clientWidth |
- </CODE> |
- <P> |
- MSHTML (Trident), Firefox (Gecko), Opera (Presto), and Safari |
- (Webkit) all support <ICODE>clientHeight</ICODE> on <ICODE>document.body</ICODE> |
- and <ICODE>document.documentElement</ICODE>. The difficulty is figuring out |
- which one is reliable. In other words which object to get the |
- <ICODE>clientHeight</ICODE> property from:<ICODE>documentElement</ICODE> or <ICODE>body</ICODE>? |
- </P> |
- |
- <P> |
- What the number returned from either of these properties |
- represents depends on the environment. The environment includes |
- the browser, its version, and the rendering mode of the document. |
- In quirks mode, we'll mostly want to use <ICODE>body.clientHeight</ICODE> |
- (except for in Safari 2). |
- </P> |
- <CODE>document.body.clientHeight</CODE> |
- <P> |
- Some environments will return the viewport height. Others will |
- return <ICODE>0</ICODE>. Yet others will return the <ICODE>clientHeight</ICODE> of |
- the <ICODE>BODY</ICODE> element. |
- </P> |
- <CODE> document.documentElement.clientHeight</CODE> |
- <P> |
- This is the more "standard" property for getting the height of |
- the viewport. It usually "works" in modern browsers in |
- <DFN>standards mode</DFN>. Notable exceptions include Safari 2 and |
- Opera <= 9.25, both of which return the <ICODE>clientHeight</ICODE> |
- of the <ICODE>html</ICODE> <EM>element</EM>. (Oddly, Opera <= 9.25 |
- in standards mode returns the width of the viewport for |
- <ICODE>documentElement.clientWidth</ICODE>). |
- </P> |
- <P> |
- With the exception of Safari 2, <ICODE>body.clientHeight</ICODE> is reliable |
- where <ICODE>documentElement.clientHeight</ICODE> is found to be unreliable. |
- For example, in Safari 3+, Opera, and Mozilla, all in quirks mode, |
- <ICODE>document.documentElement.clientHeight</ICODE> returns the <ICODE>clientHeight</ICODE> |
- of the <ICODE>html</ICODE> element (this may seem unsurprising but |
- it is not what we want). |
- </P> |
- <P> |
- Conversely, <ICODE>document.body.clientHeight</ICODE> will return |
- the height of the viewport in most cases where |
- <ICODE>document.documentElement.clientHeight</ICODE> does not. An exception |
- to that is Safari 2, where <ICODE>documentElement.clientHeight</ICODE> |
- and <ICODE>body.clientHeight</ICODE> both return the height of their |
- corresponding element (not what we want). |
- </P> |
- <P> |
- By using a combination of <DFN>Feature Testing</DFN> and <DFN>Capability Testing</DFN>, |
- the dimensions of the viewport can be strategically retrieved |
- from the property that works in the environment the script is |
- running in. The trick is determining which property will give us |
- the value we want. |
- </P> |
- <P> |
- Since <ICODE>document.clientHeight</ICODE> is reliable where |
- (rarely) supported, and since browsers that support this property |
- don't return the viewport dimensions from |
- <ICODE>document.body.clientHeight</ICODE> or |
- <ICODE>document.documentElement.clientHeight</ICODE>, this should be the |
- very first condition: |
- </P> |
- <CODE> |
-// Safari 2 uses document.clientWidth (default). |
-if(typeof document.clientWidth == "number") { |
- // use document.clientWidth. |
-} |
- </CODE> |
- <P> |
- The next strategy is to determine if |
- <ICODE>document.documentElement.clientHeight</ICODE> property is unreliable. |
- It is deemed "unreliable" when it is either <ICODE>0</ICODE> or taller |
- than the viewport. |
- </P> |
- <P> |
- Determining if <ICODE>documentElement.clientHeight</ICODE> is <ICODE>0</ICODE> is easy. |
- The result is stored in a variable <ICODE>IS_BODY_ACTING_ROOT</ICODE>. |
- </P> |
- <CODE> |
-var docEl = document.documentElement, |
- IS_BODY_ACTING_ROOT = docEl && docEl.clientHeight === 0; |
-docEl = null; |
- </CODE> |
- <P> |
- To determine if <ICODE>documentElement.clientHeight</ICODE> returns |
- a value taller than the viewport, we need a <DFN>Capability Test.</DFN> |
- </P> |
- <P> |
- If we can force <ICODE>documentElement</ICODE> to be very tall |
- (taller than a normal viewport) we can then check to see if |
- <ICODE>documentElement.clientHeight</ICODE> returns that "very tall" number. |
- If it does, then it is unreliable. |
- </P> |
- <P> |
- We can force <ICODE>documentElement</ICODE> to be taller than the viewport |
- (or any "normal" viewport) by adding a <ICODE>div</ICODE> to the <ICODE>body</ICODE>, |
- give that <ICODE>div</ICODE> a height larger than any normal monitor, |
- and then check to see if <ICODE>documentElement.clientHeight</ICODE> is |
- that high (or "almost" that high, to account for <ICODE>documentElement</ICODE> |
- having a border). |
- </P> |
- <CODE> |
-// Used to feature test Opera returning wrong values |
-// for documentElement.clientHeight. |
-// The results of this function should be cached, |
-// so it does not need to be called more than once. |
-function isDocumentElementHeightOff(){ |
- var d = document, |
- div = d.createElement('div'); |
- div.style.height = "2500px"; |
- d.body.insertBefore(div, d.body.firstChild); |
- var r = d.documentElement.clientHeight > 2400; |
- d.body.removeChild(div); |
- return r; |
-} |
- </CODE> |
- <P> |
- We can use this function to see if we should use |
- <ICODE>body.clientHeight</ICODE>, instead. (but only after checking if |
- <ICODE>document.clientHeight</ICODE> is supported). |
- </P> |
- <CODE> |
-// Safari 2 uses document.clientWidth (default). |
-if(typeof document.clientWidth == "number") { |
- // use document.clientHeight/Width. |
-} |
-else if(IS_BODY_ACTING_ROOT || isDocumentElementHeightOff()) { |
- // use document.body.clientHeight/Width. |
-} else { |
- // use document.documentElement.clientHeight/Width. |
-} |
- </CODE> |
- <P> |
- The preceding strategy was developed by Garrett Smith with input |
- from John David Dalton. A complete and tested example can be found |
- in APE Library under <ICODE>APE.dom.getViewportDimensions</ICODE>. |
- Source code: |
- <URL>http://dhtmlkitchen.com/ape/build/dom/viewport-f.js</URL>. |
- APE is publicly released under Academic Free License. |
- APE home: <URL>http://dhtmlkitchen.com/ape/</URL>. |
- </P> |
- <P> |
- Note: The dimensions cannot be determined accurately until after |
- the document has finished loading. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms533566%28VS.85%29.aspx</URL> |
- <URL>http://developer.mozilla.org/en/DOM/window.innerWidth</URL> |
- <URL>http://dev.opera.com/articles/view/using-capability-detection/</URL> |
- </MOREINFO> |
- </CONTENT> |
- |
- <CONTENT TITLE="How do I check to see if a child window is open, before opening another?" |
- ID="isWindowOpen" NUMID="4_10"> |
- <CODE> |
-var myWin; |
-function openWin(aURL) { |
- if (!myWin || myWin.closed ) { |
- myWin = window.open(aURL,'myWin'); |
- } else { |
- myWin.location.href = aURL; |
- myWin.focus(); |
- } |
-} |
- </CODE> |
- <P> |
- Popup windows cause usability problems and are generally best avoided. |
- </P> |
- <MOREINFO> |
- <URL>https://developer.mozilla.org/en/DOM:window.open</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/ms533574%28VS.85%29.aspx</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/window.htm#1201877</URL> |
- <URL>http://www.useit.com/alertbox/990530.html</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="Why does framename.print() not print the correct frame in IE?" |
- ID="printFrame" NUMID="4_11"> |
- <P> |
- IE prints the frame that has focus when you call the print |
- method <ICODE>frameref.focus();frameref.print();</ICODE> |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms976105.aspx</URL> |
- </MOREINFO> |
- </CONTENT> |
- |
- <CONTENT TITLE="How do I close a window and why does it not work on the first one?" |
- ID="windowClose" NUMID="4_14"> |
- <P> |
- If a window was opened by javascript, then it can be closed |
- without confirmation by using <ICODE>windowRef.close()</ICODE>. |
- </P> |
- <P> |
- Before calling <ICODE>windowRef.close()</ICODE> (or other <ICODE>window</ICODE> methods), make |
- sure the window reference is not null and its <ICODE>closed</ICODE> property is <ICODE>false</ICODE>. |
- </P> |
- <P> |
- Popup windows cause usability problems and are generally best avoided. |
- </P> |
- <MOREINFO> |
- <URL>http://www.useit.com/alertbox/990530.html</URL> |
- <URL>#isWindowOpen</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx</URL> |
- <URL>https://developer.mozilla.org/en/DOM/window.close#Description</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/window.htm#1201822</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="Why do I get permission denied when accessing a frame/window?" |
- ID="permissionDenied" NUMID="4_19"> |
- <P> |
- In the normal browser security model, a script may only access the |
- properties of documents served from the same domain or IP address, |
- protocol, and port. |
- </P> |
- <P> |
- Any attempt to access a property in such cases will result in a "Permission |
- Denied" error. Signed scripts or trusted ActiveX objects can |
- overcome this in limited situations. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms533028%28VS.85%29.aspx</URL> |
- <URL>https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I make a 10 second delay?" ID="setTimeout" NUMID="4_20"> |
- <P> |
- There is no built-in way to pause execution in javascript such |
- as a sleep function, but hosts usually provide a method of some |
- form. Web browsers are designed for event driven programming and |
- only provide the <ICODE>setTimeout</ICODE> and <ICODE>setInterval</ICODE> functions |
- to facilitate timed delays. The delay before calling <ICODE>getSnork</ICODE> may |
- exceed the second parameter to <ICODE>setTimeout</ICODE> and <ICODE>setInterval</ICODE> |
- due to implementation differences among browsers. |
- </P> |
- <P> |
- To call the function <ICODE>getSnork</ICODE>, approximately 10 seconds |
- after the function <ICODE>getMoomin()</ICODE> completes, you would do this: |
- </P> |
- <CODE> |
-getMoomin(); |
-setTimeout(getSnork, 10000); |
- </CODE> |
- <P> |
- Script execution is not stopped, and adding <ICODE>getSnufkin()</ICODE> after the |
- <ICODE>setTimeout</ICODE> line would immediately execute the function <ICODE>getSnufkin</ICODE> |
- before <ICODE>getSnork</ICODE>. |
- </P> |
- <P> |
- Achieving delays through running a loop of some sort for a pre-defined |
- period is a bad strategy, as that will inhibit whatever was supposed to |
- be happening during the delay, including blocking user interation. |
- </P> |
- <P> |
- Other (less event driven) hosts have different wait functions, |
- such as <ICODE>WScript.Sleep()</ICODE> in the Windows Script Host. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/window.htm#1203758</URL> |
- <URL>http://en.wikipedia.org/wiki/Event-driven_programming</URL> |
- <URL>faq_notes/misc.html#mtSetTI</URL> |
- </MOREINFO> |
- </CONTENT> |
- |
- <CONTENT TITLE="How do I change print settings for window.print()?" |
- ID="printSettings" NUMID="4_23"> |
- <P> |
- In a normal security environment, you can't change anything. |
- </P> |
- <P> |
- Print Stylesheet rules provide options. |
- </P> |
- <P> |
- For IE, <ICODE>ActiveX</ICODE> or Plugin ScriptX and |
- Neptune from Meadroid to give you more control for Windows |
- versions of Internet Explorer, Netscape, and Opera. |
- </P> |
- <MOREINFO> |
- <URL>http://www.meadroid.com/scriptx/</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/ms976105.aspx</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I change the confirm box to say yes/no or default to cancel?" |
- ID="changeBrowserDialog" NUMID="4_28"> |
- <P> |
- The buttons on a confirm box cannot be changed, nor can a default |
- button be specified. |
- </P> |
- <P> |
- Change the question to a statement so that "OK" is suitable as the |
- default response. |
- </P> |
- <P> |
- Example: |
- "Would you like us to charge your credit card?" (wrong) |
- "We will now charge your credit card." (right). |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="How do I prompt a "Save As" dialog for an accepted mime type?" |
- ID="fileDownload" NUMID="4_33"> |
- <P> |
- It is not possible with client-side javascript. |
- </P> |
- <P> |
- Some browsers accept the Content-Disposition header, but this |
- must be added by the server. Taking the form:- |
- <ICODE>Content-Disposition: attachment; filename=filename.ext</ICODE> |
- </P> |
- <MOREINFO> |
- <URL>http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html</URL> |
- <URL>http://support.microsoft.com/kb/q260519/</URL> |
- </MOREINFO> |
- </CONTENT> |
- <!-- Can we remove this entry? |
- http://groups.google.com/group/comp.lang.javascript/msg/c70b57d86300fa91 |
- |
- CONTENT TITLE="I have window.status="Moomin"; why doesn't the statusbar change?" |
- ID="returnValue" NUMID="4_35"> |
- <P> |
-When changing the status in an event (e.g. <ICODE>onmouseover</ICODE>) you |
-should return true from the event. Also a number of browsers |
-require a short delay before setting the status to overcome their |
-default behaviour with the statusbar. |
-<ICODE>onevent="setTimeout('window.status=\'Moomin\'',15);"</ICODE> |
- </P> |
- <P> |
-Many browsers are configured, by default, to disallow scripts from setting |
-the status bar text. Some browsers don't have such a bar, or don't have it by default. |
- </P> |
- </CONTENT--> |
- |
- <CONTENT TITLE="How do I modify the current browser window?" ID="modifyChrome" NUMID="4_36"> |
- <P> |
- In a default security environment you are very limited in how much |
- you can modify the current browser window. You can use |
- <ICODE>window.resizeTo</ICODE> or <ICODE>window.moveTo</ICODE> to resize or move a |
- window respectively, but that is it. Normally you can only |
- suggest chrome changes in a <ICODE>window.open</ICODE>. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms536651%28VS.85%29.aspx</URL> |
- <URL>https://developer.mozilla.org/en/DOM:window.open</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I POST a form to a new window?" ID="target" NUMID="4_37"> |
- <P> |
- Use the target attribute on the form, opening a window with |
- that name and your feature string in the onsubmit handler of the |
- FORM. |
- </P> |
- <CODE> |
-<form action="" method="post" |
- target="wndname" onsubmit="window.open('',this.target);return true;"> |
- </CODE> |
- <MOREINFO> |
- <URL>http://www.htmlhelp.com/reference/html40/forms/form.html</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I open a new window with javascript?" ID="openWindow" NUMID="4_42"> |
- <P> |
- New windows can be opened on browsers that support the |
- <ICODE>window.open</ICODE> function and are not subject to the action of any |
- pop-up blocking mechanism with code such as:- |
- </P> |
- <CODE> |
-var wRef; |
-if(window.open){ |
- wRef = window.open("http://example.com/page.html","windowName"); |
-} |
- </CODE> |
- <MOREINFO> |
- <URL>https://developer.mozilla.org/en/DOM:window.open</URL> |
- <URL>http://www.infimum.dk/HTML/JSwindows.html</URL> |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/windows.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/resources.xml |
=================================================================== |
--- cljs/sections/resources.xml (revision 25) |
+++ cljs/sections/resources.xml (nonexistent) |
@@ -1,178 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Javascript Resources" ID="ecmascriptResources" NUMID="3"> |
- <CONTENT TITLE="What books are recommended for javascript?" ID="books" NUMID="3_1"> |
- <P> |
- Most javascript books have been found to contain so many technical |
- errors that consensus recommendations have not emerged from the group. |
- </P> |
- <P> |
- The following books have been considered to have value by some |
- individuals on c.l.js. The reviews of these books are provided: |
- </P> |
- <LIST TYPE="UL"> |
- <LI><EM>"JavaScript: The Definitive Guide,"</EM> 5th Edition, by David Flanagan |
- <UL> |
- <LI>Published: 2006-08</LI> |
- <LI>Pages: 1018</LI> |
- <LI>Errata: <URL>http://oreilly.com/catalog/9780596101992/errata/</URL></LI> |
- <LI>Discussed in: |
- <UL> |
- <LI> |
- <URL LINKTEXT="FAQ Update 9.85 Dated 2007-08-31" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/7283898f77fd2a66/9252aa024e058dea#c5f145ae807c918e</URL> |
- </LI> |
- </UL> |
- </LI> |
- </UL> |
- </LI> |
- <LI> |
- <EM>"JavaScript, The Good Parts,"</EM> 1st Edition, by Douglas Crockford |
- <UL> |
- <LI>Published: 2008-05</LI> |
- <LI>Pages: 170</LI> |
- <LI>Errata: <URL>http://oreilly.com/catalog/9780596517748/errata/</URL></LI> |
- <LI>Discussed in: |
- <UL> |
- <LI> |
- <URL LINKTEXT="Crockford's 'The Good Parts': a short review" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/d084d2109f7b4ec7#</URL> |
- </LI> |
- <LI> |
- <URL LINKTEXT="FunctionExpression's and memory consumptions" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/db1e49ab113aa05c/3987eac87ad27966#3987eac87ad27966</URL> |
- </LI> |
- <LI> |
- <URL LINKTEXT="FAQ Topic - What books are recommended for javascript? (2008-12-02)" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/6a41f7835ee728de/da5ccfc65e2df64a#da5ccfc65e2df64a</URL> |
- </LI> |
- <LI> |
- <URL LINKTEXT="Augmenting functions" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/3a08fb741525ab6d/</URL> |
- </LI> |
- |
- <LI> |
- <URL LINKTEXT="Crockford's JavaScript, The Good Parts (a book review)." |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/bf26be6e63494ee2/acb733a1c35f6ce5#ee9e4ee29e658d5d</URL> |
- </LI> |
- <LI> |
- <URL LINKTEXT="Closures Explained" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/df602506ee48b400/e65e00f5cad07676#e65e00f5cad07676</URL> |
- </LI> |
- <LI> |
- <URL LINKTEXT="Javascript library development" |
- >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/acadf1b22b219433/4f69a95607d0b3ae#4f69a95607d0b3ae</URL> |
- </LI> |
- </UL></LI> |
- </UL> |
- </LI> |
- </LIST> |
- </CONTENT> |
- |
- <CONTENT TITLE="What online resources are available?" ID="onlineResources" NUMID="3_2"> |
- <LIST TITLE="ECMAScript" TYPE="DL" ID="ecmaResources"> |
- <DT>The Official ECMAScript Specification</DT> |
- <DD><URL>[ECMA-262] http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm</URL></DD> |
- |
- <DT>[ISO16262] ISO/IEC 16262, Second Edition 2002-06-01 : ISO Standard matching |
- ECMA-262 3rd Edition, with corrections.</DT> |
- <DD><URL>http://standards.iso.org/ittf/PubliclyAvailableStandards/c033835_ISO_IEC_16262_2002(E).zip</URL></DD> |
- |
- <DT>[MS-ES3]: Internet Explorer ECMA-262 ECMAScript Language Specification Standards Support</DT> |
- <DD><URL>http://msdn.microsoft.com/en-us/library/ff520996%28VS.85%29.aspx</URL></DD> |
- <DD><URL>res/%5BMS-ES3%5D.pdf</URL> (local alias)</DD> |
- |
- <DT>[MS-ES3EX]: Microsoft JScript Extensions to the ECMAScript Language Specification Third Edition</DT> |
- <DD><URL>http://msdn.microsoft.com/en-us/library/ff521046%28VS.85%29.aspx</URL></DD> |
- <DD><URL>res/%5BMS-ES3EX%5D.pdf</URL> (local alias)</DD> |
- |
- <DT>ECMAScript on Wikipedia</DT> |
- <DD><URL>http://en.wikipedia.org/wiki/ECMAScript</URL></DD> |
- </LIST> |
- |
- <LIST TITLE="W3C DOM" TYPE="DL" ID="domResources"> |
- <DT>DOM Level 1 ECMAScript Binding</DT> |
- <DD><URL>http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html</URL></DD> |
- |
- <DT>DOM Level 2 ECMAScript Binding</DT> |
- <DD><URL>http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html</URL></DD> |
- |
- <DT>DOM Level 2 Events</DT> |
- <DD><URL>http://www.w3.org/TR/DOM-Level-2-Events/events.html</URL></DD> |
- |
- <DT>DOM Level 2 Style</DT> |
- <DD><URL>http://www.w3.org/TR/DOM-Level-2-Style/</URL></DD> |
- |
- <DT>DOM Level 3 ECMAScript Binding</DT> |
- <DD><URL>http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html</URL></DD> |
- </LIST> |
- |
- <LIST TITLE="Browser Documentation" TYPE="DL" ID="browserResources"> |
- <DT>Mozilla</DT> |
- <DD>JavaScript: <URL>http://developer.mozilla.org/en/docs/JavaScript</URL></DD> |
- <DD>Gecko DOM Reference: <URL>http://developer.mozilla.org/en/docs/Gecko_DOM_Reference</URL></DD> |
- |
- <DT>Microsoft</DT> |
- <DD>HTML and DHTML Reference: <URL>http://msdn.microsoft.com/en-us/library/ms533050.aspx</URL></DD> |
- <DD>JScript Language Reference:<URL>http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx</URL></DD> |
- <DD>Scripting: <URL>http://msdn.microsoft.com/en-us/library/ms950396.aspx</URL></DD> |
- |
- <DT>Opera</DT> |
- <DD>Web Specifications Support: <URL>http://www.opera.com/docs/specs/#ecmascript</URL></DD> |
- |
- <DD>JavaScript Support: <URL>http://www.opera.com/docs/specs/js/</URL></DD> |
- <DD>ECMAScript Support: <URL>http://www.opera.com/docs/specs/js/ecma</URL></DD> |
- |
- <DT>BlackBerry JavaScript Reference</DT> |
- <DD><URL>http://docs.blackberry.com/en/developers/deliverables/11849/</URL></DD> |
- |
- <DT>ICab InScript</DT> |
- <DD><URL>http://www.muchsoft.com/inscript/</URL></DD> |
- |
- <DT>Apple Safari</DT> |
- <DD>Web Content Guide: <URL>http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html</URL></DD> |
- |
- <DT>Webkit</DT> |
- <DD>Project Site: <URL>http://webkit.org/</URL></DD> |
- <DD>Wiki: <URL>http://trac.webkit.org/wiki</URL></DD> |
- <DD>DOM Reference: <URL>http://developer.apple.com/Mac/library/documentation/AppleApplications/Reference/WebKitDOMRef/index.html#//apple_ref/doc/uid/TP40006089</URL></DD> |
- |
- <DT>Netscape 4 Client-Side JavaScript Reference</DT> |
- <DD><URL>http://docs.sun.com/source/816-6408-10/</URL></DD> |
- |
- <DT>Archived documentation for MSIE 3.x</DT> |
- <DD><URL>http://members.tripod.com/%7Ehousten/download/</URL></DD> |
- </LIST> |
- |
- <LIST TITLE="Standalone ECMAScript Implementations" TYPE="DL" ID="standaloneImplementations"> |
- <DT>Rhino: An open-source implementation of JavaScript written in Java</DT> |
- <DD><URL>http://www.mozilla.org/rhino/</URL></DD> |
- |
- <DT>Besen IDE: ECMAScript Edition 5 with IDE</DT> |
- <DD><URL>http://besen.sourceforge.net/</URL></DD> |
- |
- <DT>V8: Google's open source JavaScript engine</DT> |
- <DD><URL>http://code.google.com/p/v8/</URL></DD> |
- |
- <DT>SpiderMonkey: Mozilla's C implementation of JavaScript</DT> |
- <DD><URL>http://www.mozilla.org/js/spidermonkey/</URL></DD> |
- |
- <DT>Digital Mars DMD Script, console and MS Active Script implementation of ECMAScript</DT> |
- <DD><URL>http://www.digitalmars.com/dscript/</URL></DD> |
- </LIST> |
- |
- <LIST TITLE="Other ECMAScript Implementations" TYPE="DL" ID="nonBrowserResources"> |
- <DT>Developing Dashboard Widgets: Apple Developer Connection</DT> |
- <DD><URL>http://developer.apple.com/macosx/dashboard.html</URL></DD> |
- |
- <DT>Whitebeam Apache Module: Server Side JavaScript in Apache</DT> |
- <DD><URL>http://www.whitebeam.org/</URL></DD> |
- </LIST> |
- </CONTENT> |
- |
- <CONTENT TITLE="Javascript Libraries" ID="libraryResources"> |
- <P> |
- No javascript libraries are endorsed by this group. If you want help |
- with using a library, visit that library's discussion group instead. |
- </P> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/resources.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/suggestions.xml |
=================================================================== |
--- cljs/sections/suggestions.xml (revision 25) |
+++ cljs/sections/suggestions.xml (nonexistent) |
@@ -1,37 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Comments and Suggestions" ID="comments" NUMID="5"> |
- <P HTMLONLY="true"> |
- This FAQ uses the CSS stylesheet <URL>faq.css</URL> and is generated |
- from the XML source <URL>index.xml</URL> using the XSLT stylesheet |
- <URL>index.xsl</URL><!-- which also checks the links -->. |
- </P> |
- <CONTENT TITLE="Why do some posts have <FAQENTRY> in them?" ID="FAQENTRY" NUMID="5_1"> |
- <P> |
- If a poster feels that the question they are answering should be |
- covered in the FAQ, placing <FAQENTRY> in the post lets the FAQ |
- robot collect the messages for easy review and inclusion. A Draft Proposal |
- for the FAQ is requested and appreciated. |
- </P> |
- <P> |
-The <FAQENTRY> should not be used in posts except in |
-conjunction with a suggestion/proposal for this FAQ. It should |
-also not be literally quoted in replies, instead it should be |
-partly obscured as, e.g. <FAQ**TRY> or similar. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="How do I make a suggestion?" NUMID="5_2" ID="makeSuggestion"> |
- <P> |
-To make a suggestion to this FAQ, use either the FAQENTRY method |
-above, or e-mail Thomas 'PointedEars' Lahn <cljs@PointedEars.de> (editor). |
-All comments, suggestions, and especially corrections are welcome. |
- </P> |
- </CONTENT> |
- <!-- FIXME --> |
- <!-- |
- <P> |
- This FAQ is (C) Copyright Contributors on behalf of the |
- newsgroup comp.lang.javascript. Upon change of the FAQ maintainer, |
- the copyright will automatically pass over to the new maintainer. |
- </P> |
- --> |
- </CONTENT> |
\ No newline at end of file |
/cljs/sections/suggestions.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/numbers.xml |
=================================================================== |
--- cljs/sections/numbers.xml (revision 25) |
+++ cljs/sections/numbers.xml (nonexistent) |
@@ -1,180 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Numbers" ID="numbers"> |
- <CONTENT TITLE="How do I format a Number as a String with exactly 2 decimal places?" ID="formatNumber" NUMID="4_6"> |
- <P> |
- When formatting money for example, to format 6.57634 to 6.58, 6.7 to |
- 6.50, and 6 to 6.00? |
- </P> |
- <P> |
- Rounding of x.xx5 is unreliable, as most numbers are not represented |
- exactly. See also: |
- <URL LINKTEXT="Why does simple decimal arithmetic give strange results?">#binaryNumbers</URL> |
- </P> |
- <P> |
- The statement <ICODE>n = Math.round(n * 100)/100</ICODE> converts <ICODE>n</ICODE> to a <ICODE>Number</ICODE> value |
- close to a multiple of <ICODE>0.01</ICODE>. However, there are some problems. |
- Converting the number to a string <ICODE>(n + "")</ICODE>, does not give |
- trailing zeroes. Rounding numbers that are very close to <ICODE>x.5</ICODE>, for example, |
- <ICODE>Math.round(0.49999999999999992)</ICODE> results <ICODE>1</ICODE>. |
- </P> |
- <P> |
- ECMA-262 3rd Edition introduced <ICODE>Number.prototype.toFixed</ICODE>. |
- There are bugs in JScript 5.8 and below with certain numbers, for example |
- <ICODE>0.007.toFixed(2)</ICODE> incorrectly results <ICODE>0.00</ICODE>. |
- </P> |
- <CODE> |
-var numberToFixed = |
-(function() { |
- return toFixedString; |
- |
- function toFixedString(n, digits) { |
- var unsigned = toUnsignedString(Math.abs(n), digits); |
- return (n < 0 ? "-" : "") + unsigned; |
- } |
- |
- function toUnsignedString(m, digits) { |
- var t, s = Math.round(m * Math.pow(10, digits)) + "", |
- start, end; |
- if (/\D/.test(s)) { |
- return "" + m; |
- } |
- s = padLeft(s, 1 + digits, "0"); |
- start = s.substring(0, t = (s.length - digits)); |
- end = s.substring(t); |
- if(end) { |
- end = "." + end; |
- } |
- return start + end; // avoid "0." |
- } |
- /** |
- * @param {string} input: input value converted to string. |
- * @param {number} size: desired length of output. |
- * @param {string} ch: single character to prefix to s. |
- */ |
- function padLeft(input, size, ch) { |
- var s = input + ""; |
- while(s.length < size) { |
- s = ch + s; |
- } |
- return s; |
- } |
-})(); |
- |
-// Test results |
-document.writeln([ |
- "numberToFixed(9e-3, 12) => " + numberToFixed(9e-3, 12), |
- "numberToFixed(1.255, 2) => " + numberToFixed(1.255, 2), |
- "numberToFixed(1.355, 2) => " + numberToFixed(1.355, 2), |
- "numberToFixed(0.1255, 3) => " + numberToFixed(0.1255, 3), |
- "numberToFixed(0.07, 2) => " + numberToFixed(0.07, 2), |
- "numberToFixed(0.0000000006, 1) => " + numberToFixed(0.0000000006, 1), |
- "numberToFixed(0.0000000006, 0) => " + numberToFixed(0.0000000006, 0) |
-].join("\n")); |
- </CODE> |
- <MOREINFO> |
- <URL>http://www.merlyn.demon.co.uk/js-round.htm</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/sstyff0z%28VS.85%29.aspx</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="Why does simple decimal arithmetic give strange results?" ID="binaryNumbers" NUMID="4_7"> |
- <P> |
- For example, <ICODE>5 * 1.015</ICODE> does not give exactly |
- <ICODE>5.075</ICODE> and <ICODE>0.06+0.01</ICODE> does |
- not give exactly <ICODE>0.07</ICODE> in javascript. |
- </P> |
- <P> |
- ECMAScript numbers are represented in binary as IEEE-754 (IEC 559) |
- Doubles, with a resolution of 53 bits, giving an accuracy of |
- 15-16 decimal digits; integers up to just over <ICODE>9e15</ICODE> are |
- precise, but few decimal fractions are. Given this, arithmetic |
- is as exact as possible, but no more. Operations on integers |
- are exact if the true result and all intermediates are integers |
- within that range. |
- </P> |
- <P> |
- In particular, non-integer results should not normally be |
- compared for equality; and non-integer computed results |
- commonly need rounding; see <URL |
- LINKTEXT="How do I format a Number as a String with exactly 2 decimal places?" |
- >#formatNumber</URL> |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/7wkd9z69%28VS.85%29.aspx</URL> |
- <URL>http://www.merlyn.demon.co.uk/js-misc0.htm#DW4</URL> |
- </MOREINFO> |
- <P> |
- Otherwise, use <ICODE>Math.round</ICODE> on the results of expressions which |
- should be of integer value. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="Why does K = parseInt('09') set K to 0?" ID="parseIntBase" NUMID="4_12"> |
- <P> |
- Method <ICODE>parseInt</ICODE> generally needs a second parameter, <ICODE>radix</ICODE>, |
- for the base (from 2 to 36). |
- </P> |
- <P> |
- If <ICODE>radix</ICODE> is omitted, the base is determined by the contents of |
- the string. Any string beginning with <ICODE>'0x'</ICODE> or <ICODE>'0X'</ICODE> represents a |
- hexadecimal number. A string beginning with a leading 0 may be parsed as |
- octal (as if <ICODE>raxix</ICODE> were 8), in ECMA-262 Ed 3 (octal digits are <ICODE>0-7</ICODE>). |
- If string <ICODE>'09'</ICODE> is converted to <ICODE>0</ICODE>. |
- </P> |
- <P> |
- To force use of a particular base, use the <ICODE>radix</ICODE> |
- parameter: <ICODE>parseInt("09", base)</ICODE>. |
- |
- <!-- [omit] |
- If base 10 is desired, |
- the unary <ICODE>+</ICODE> operator can be an option. Example: |
- <ICODE> |
-var s = '-09.1'; // Input string. |
-var j = +s; // Convert to number. Result: -9.1 |
-var n = j|0; // Chop off decimal (convert ToInt32). Result: -9 |
-</ICODE> |
- [/omit] --> |
- </P> |
- <MOREINFO> |
- <URL>http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/toplev.htm#1064173</URL> |
- <URL>notes/type-conversion/#tcPrIntRx</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="Why does 1+1 equal 11? or How do I convert a string to a number?" ID="typeConvert"> |
- <P> |
- Variables are not typed; their values are. The conversion between a |
- string and a number happens automatically. |
- </P> |
- <P> |
- The addition operator (<ICODE>+</ICODE>) performs concatenation if either operand is a |
- string, thus <ICODE>"1" + 1</ICODE> results <ICODE>"11"</ICODE>. To perform addition, you might need |
- to first convert the string to a number. For example <ICODE>+varname</ICODE> or |
- <ICODE>Number(varname)</ICODE> or <ICODE>parseInt(varname, 10)</ICODE> or |
- <ICODE>parseFloat(varname)</ICODE>. Form control values are strings, as is the result |
- from a <ICODE>prompt</ICODE> dialog. Convert these to numbers before performing |
- addition: <ICODE>+'1' + 1</ICODE> results <ICODE>2</ICODE>. |
- </P> |
- <MOREINFO> |
- <URL LINKTEXT="Additional Notes">notes/type-conversion/</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/67defydd%28VS.85%29.aspx</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I generate a random integer from 1 to n?" ID="randomNumber" NUMID="4_22"> |
- <P> |
- <ICODE>Math.random()</ICODE> returns a value <ICODE>R</ICODE> such that <ICODE>0 <= R < 1.0</ICODE>; therefore: |
- </P> |
- <CODE> |
-// positive integer expected |
-function getRandomNumber(n) { |
- return Math.floor(n * Math.random()); |
-} |
- </CODE> |
- - gives an evenly distributed random integer in the range from |
- <ICODE>0</ICODE> to <ICODE>n - 1</ICODE> inclusive; use <ICODE>getRandomNumber(n)+1</ICODE> for <ICODE>1</ICODE> to <ICODE>n</ICODE>. |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx</URL> |
- <URL>http://docs.sun.com/source/816-6408-10/math.htm</URL> |
- How to Deal and Shuffle, see in: <URL>http://www.merlyn.demon.co.uk/js-randm.htm</URL> |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/numbers.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/debugging.xml |
=================================================================== |
--- cljs/sections/debugging.xml (revision 25) |
+++ cljs/sections/debugging.xml (nonexistent) |
@@ -1,116 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Debugging" ID="debugging"> |
- <CONTENT TITLE="How do I get my browser to report javascript errors?" |
- ID="javascriptErrors" NUMID="4_43"> |
- <P> |
-There are debugging tools for many browsers. Learn to use them all. |
- </P> |
- <LIST TYPE="DL"> |
- <DT>Windows</DT> |
- <DD> |
-<URL LINKTEXT="Fiddler">http://www.fiddlertool.com/fiddler/</URL>. |
-Fiddler is an HTTP Debugging proxy (it won't find script |
-errors). Fiddler logs HTTP activity, like Firebug's Net |
-tab, but can be attached to any browser running on Windows. |
- </DD> |
- <DT>Windows IE</DT> |
- <DD>Microsoft Script Editor. Included with Visual Studio or Microsoft |
-Word 2003 (discontinued in Office 2007). |
-To enable, |
-<ICODE>Tools</ICODE>, <ICODE>Internet Options</ICODE>, <ICODE>Advanced</ICODE>, and uncheck |
-<ICODE>Disable Script Debugging</ICODE>. After enabling Script Debugging, |
-a <ICODE>Script Debugger</ICODE> option will appear in the <ICODE>View</ICODE> menu.</DD> |
- |
-<DD><URL LINKTEXT="IETester">http://www.my-debugbar.com/wiki/IETester/HomePage</URL> for testing IE 5.5- IE8.</DD> |
-<DD><URL LINKTEXT="CompanionJS">http://www.my-debugbar.com/wiki/CompanionJS/HomePage</URL> <ICODE>console</ICODE> for IE.</DD> |
- <DD> |
-<EM>Note:</EM> For debugging scripts in IE, the Microsoft Script <EM>Editor</EM> |
-is recommended. However, if not available, the <URL LINKTEXT="Microsoft Script Debugger" |
->http://www.microsoft.com/downloads/details.aspx?FamilyId=2F465BE0-94FD-4569-B3C4-DFFDF19CCD99&displaylang=en</URL> may be somewhat helpful. |
- </DD> |
- <DD> |
-<URL LINKTEXT="Internet Explorer Developer Toolbar" |
- >http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en</URL> |
- </DD> |
- <DD> |
-To report errors: Wait until a little yellow |
-triangle appears at the left end of the status bar, double click |
-on it and, when the error dialog box appears, check the "Always |
-show errors" checkbox it contains. |
- |
-Or, <ICODE>Internet Options</ICODE>, <ICODE>Advanced</ICODE>, deselect <ICODE>"Disable Script Debugging"</ICODE>, |
-select <ICODE>"Display a notification ..."</ICODE>. |
- </DD> |
- <DT>Firefox</DT> |
- <DD> |
- <ICODE>Tools > Error console</ICODE> (<ICODE>Ctrl</ICODE> + <ICODE>Shift</ICODE> + <ICODE>j</ICODE>). |
- </DD> |
- <DD> |
-<URL LINKTEXT="Firebug">http://getfirebug.com/</URL> |
- </DD> |
- <DD> |
-<URL LINKTEXT="YSlow">https://addons.mozilla.org/en-US/firefox/addon/5369</URL>. |
-YSlow analyzes web pages and tells you why they're slow |
-based on Yahoo's rules for high performance web sites. |
- </DD> |
- <DD> |
-<URL LINKTEXT="Lori">https://addons.mozilla.org/en-US/firefox/addon/1743</URL> |
-<DFN>Lori</DFN> or Life-of-request info, is useful for troubleshooting |
-server response and page load time. |
- </DD> |
- <DD> |
-<URL LINKTEXT="Web Developer Toolbar">https://addons.mozilla.org/en-US/firefox/addon/60</URL>. |
- </DD> |
- <DD> |
-<URL LINKTEXT="Cookie Watcher">https://addons.mozilla.org/en-US/firefox/addon/1201</URL>. |
- </DD> |
- <DD> |
-<URL LINKTEXT="XPather">https://addons.mozilla.org/en-US/firefox/addon/1192</URL>. |
-XPath generator, editor and inspector. |
- </DD> |
- <DT>Opera</DT> |
- <DD> |
-Tools > Advanced > Error console |
- </DD> |
- <DD> |
-<URL LINKTEXT="Introduction to Opera Dragonfly" |
- >http://dev.opera.com/articles/view/introduction-to-opera-dragonfly/</URL> |
- </DD> |
- <DT>Safari</DT> |
- <DD> |
-To display the <ICODE>Develop</ICODE> menu in Safari 3.1 or higher, select |
-the checkbox labeled "Show Develop menu in menu bar" in |
-Safari's <ICODE>Advanced</ICODE> Preferences panel. |
- </DD> |
- <DD> |
-<URL LINKTEXT="Safari Web Inspector">http://trac.webkit.org/wiki/Web%20Inspector </URL> |
- </DD> |
- <DT>Chrome</DT> |
- <DD> |
-JavaScript Console: click the <ICODE>Page</ICODE> menu icon and select |
-<ICODE>Developer > JavaScript Console</ICODE>. From here, you'll be |
-able to view errors in the JavaScript execution, and enter |
-additional javascript commands to execute. |
- </DD> |
- <DD> |
-JavaScript Debugger: available as <ICODE>Page</ICODE> menu icon > <ICODE>Developer</ICODE> |
-> Debug JavaScript, the debugger provides a command prompt from which you |
-can set breakpoints, backtrace, and more. Type <ICODE>help</ICODE> at the debugger |
-command line to get started. |
- </DD> |
- <DD> |
- <UL> |
- <LI><URL LINKTEXT="Google Chrome Script Debugging" |
- >http://www.google.com/chrome/intl/en/webmasters-faq.html#jsexec</URL></LI> |
- <LI><URL LINKTEXT="Developer Tools for Google Chrome" |
- >http://blog.chromium.org/2009/06/developer-tools-for-google-chrome.html</URL></LI> |
- <LI><URL LINKTEXT="Tools for Eclipse Users">http://blog.chromium.org/2009/08/google-chrome-developer-tools-for.html</URL></LI> |
- </UL> |
- </DD> |
- <DT>Mac IE</DT> |
- <DD> |
-Use the Preferences dialog. |
- </DD> |
- </LIST> |
- </CONTENT> |
- </CONTENT> |
\ No newline at end of file |
/cljs/sections/debugging.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/dom.xml |
=================================================================== |
--- cljs/sections/dom.xml (revision 25) |
+++ cljs/sections/dom.xml (nonexistent) |
@@ -1,188 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="DOM and Forms" ID="domRef"> |
- <CONTENT TITLE="How do I get the value of a form control?" |
- ID="formControlAccess" NUMID="4_13"> |
- <P> |
- In HTML documents, a form may be referred to as a property of the |
- <ICODE>document.forms</ICODE> collection, either by its ordinal index or by name |
- (if the <ICODE>form</ICODE> has a name). A <ICODE>form</ICODE>'s controls may be similarly referenced |
- from its <ICODE>elements</ICODE> collection: |
- </P> |
- <CODE> |
-var frm = document.forms[0]; |
-var control = frm.elements["elementname"]; |
- </CODE> |
- <P> |
- Once a reference to a control is obtained, its (string) <ICODE>value</ICODE> |
- property can be read:- |
- </P> |
- <CODE> |
-var value = control.value; |
-value = +control.value; //string to number. |
- </CODE> |
- Some exceptions would be: |
- <P> |
- First Exception: Where the control is a <ICODE>SELECT</ICODE> element, and |
- support for older browsers, such as NN4, is required: |
- </P> |
- <CODE> |
-var value = control.options[control.selectedIndex].value; |
- </CODE> |
- <P> |
- Second Exception: Where several controls share the same name, |
- such as radio buttons. These are made available as collections |
- and require additional handling. For more information, see:- |
- </P> |
- <MOREINFO> |
- <URL>notes/form-access/</URL> |
- <URL LINKTEXT="Unsafe Names for HTML Form Controls">names/</URL> |
- </MOREINFO> |
- <P> |
- Third Exception: File inputs. Most current browsers do not allow |
- reading of <ICODE>type="file"</ICODE> input elements in a way that is useful. |
- </P> |
- </CONTENT> |
- <CONTENT TITLE="My element is named myselect[], how do I access it?" ID="propertyAccess" NUMID="4_25"> |
- <P> |
-Form controls with any "illegal" characters can be accessed with |
-<ICODE>formref.elements["myselect[]"]</ICODE> - The bracket characters, |
-amongst others, are illegal in ID attributes and javascript |
-identifiers, so you should try to avoid them as browsers may |
-handle them incorrectly. |
- </P> |
- <MOREINFO> |
- <URL>http://msdn.microsoft.com/en-us/library/ms537449%28VS.85%29.aspx</URL> |
- <URL>https://developer.mozilla.org/en/DOM/form</URL> |
- <URL>notes/form-access/</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="Why doesn't the global variable "divId" always refer to the element with id="divId"?" |
- ID="globalPollution" NUMID="4_41"> |
- <P> |
- Microsoft introduced a shortcut that can be used to reference |
- elements which include an <ICODE>id</ICODE> attribute where the |
- <ICODE>id</ICODE> becomes a globally-accessible property. Some browsers reproduce |
- this behavior. Some, most notably Gecko-based browsers (Netscape and Mozilla), |
- do so only in "quirks" mode. The best approach is the <ICODE>document.getElementById</ICODE> |
- method, which is part of the W3C DOM standard and implemented |
- in modern browsers (including IE from version 5.0). So an |
- element with <ICODE>id="foo"</ICODE> can be referenced |
- with:- |
- </P> |
- <CODE> |
-var el = document.getElementById("foo"); |
- </CODE> |
- <P> |
- Note: make sure not to use the same <ICODE>id</ICODE> twice in the same document |
- and do not give an element a <ICODE>name</ICODE> that matches an <ICODE>id</ICODE> |
- of another in the same document or it will trigger bugs in MSIE <= 7 with |
- <ICODE>document.getElementsByName</ICODE> and <ICODE>document.getElementById</ICODE>. |
- </P> |
- <MOREINFO> |
- <URL>https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM#Accessing_Elements_with_the_W3C_DOM</URL> |
- <URL>faq_notes/faq_notes.html#FAQN4_41</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How do I modify the content of the current page?" |
- ID="updateContent" NUMID="4_15"> |
- <P> |
- Using the non-standard but widely implemented |
- <ICODE>innerHTML</ICODE> property: |
- <ICODE><div id="anID">Some Content</div></ICODE> with script: |
- </P> |
- <CODE> |
-document.getElementById("anID").innerHTML = |
- "Some <em>new</em> Content"; |
- </CODE> |
- <P> |
- Where <ICODE>"anID"</ICODE> is the (unique on the HTML page) |
- <ICODE>id</ICODE> attribute value of the element to modify. |
- </P> |
- <P> |
- All versions of Internet Explorer exhibit problems with innerHTML, including: |
- </P> |
- <LIST TYPE="UL"> |
- <LI>Fails with FRAMESET, HEAD, HTML, STYLE, SELECT, |
- OBJECT, and all TABLE-related elements.</LI> |
- <LI>Replaces consecutive whitespace characters with a single space.</LI> |
- <LI>Changes attribute values and order of appearance.</LI> |
- <LI>Removes quotations around attribute values.</LI> |
- </LIST> |
- <P> |
- If the new content is only text and does not need to replace existing HTML, |
- it is more efficient to modify the <ICODE>data</ICODE> property of a text node. |
- </P> |
- <CODE> |
-document.getElementById("anID").firstChild.data = "Some new Text"; |
- </CODE> |
- <P> |
- Compatibility Note: Implementations have been known to split long text |
- content among several adjacent text nodes, so replacing the data of the |
- first text node may not replace all the element's text. The <ICODE>normalize</ICODE> |
- method, where supported, will combine adjacent text nodes. |
- </P> |
- <P> |
- Note: Make sure the element exists in the document (has been parsed) before trying to |
- reference it. |
- </P> |
- <MOREINFO> |
- <URL>http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-FF21A306</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/cc304097%28VS.85%29.aspx</URL> |
- <URL>http://msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx</URL> |
- <URL>http://developer.mozilla.org/en/Whitespace_in_the_DOM</URL> |
- <URL>http://developer.mozilla.org/en/docs/DOM:element.innerHTML</URL> |
- <URL>http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm</URL> (draft) |
- </MOREINFO> |
- </CONTENT> |
- |
- <CONTENT TITLE="Why does my code fail to access an element?" ID="accessElementBeforeDefined"> |
- <P> |
- An element can only be accessed after it exists in the document. |
- </P> |
- <P> |
- Either: |
- A) include your script after the HTML element it refers to, or |
- B) use the <ICODE>"load"</ICODE> event to trigger your script. |
- </P> |
- <P> |
- Example A: |
- </P> |
- <CODE> |
-<div id="snurgle">here</div> |
-<script type="text/javascript"> |
-// Don't forget var. |
-var snurgleEl = document.getElementById("snurgle"); |
-window.alert(snurgleEl.parentNode); |
-</script> |
- </CODE> |
- <P> |
- Example B: |
- </P> |
- <CODE> |
-// In the HEAD. |
-<script type="text/javascript"> |
-window.onload = function(){ |
- var snurgleEl = document.getElementById("snurgle"); |
-}; |
-</script> |
- </CODE> |
- |
- <LIST TYPE="UL" TITLE="Other problems can include:"> |
- <LI>invalid HTML</LI> |
- <LI>two elements with the same <ICODE>name</ICODE> or <ICODE>id</ICODE></LI> |
- <LI>use of an unsafe name: http://jibbering.com/names/</LI>. |
- </LIST> |
- </CONTENT> |
- <CONTENT TITLE="How can I see in javascript if a web browser accepts cookies?" |
- ID="testCookie" NUMID="4_4"> |
- <P> |
- Write a cookie and read it back and check if it's the same. |
- </P> |
- <MOREINFO> |
- Additional Notes: |
- <URL>http://www.ietf.org/rfc/rfc2965.txt</URL> |
- <URL>http://www.galasoft-lb.ch/myjavascript/consulting/2001012701/</URL> |
- <URL>http://www.cookiecentral.com/</URL> |
- </MOREINFO> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/dom.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/sections/dates.xml |
=================================================================== |
--- cljs/sections/dates.xml (revision 25) |
+++ cljs/sections/dates.xml (nonexistent) |
@@ -1,99 +0,0 @@ |
-<?xml version="1.0" encoding="UTF-8"?> |
-<CONTENT TITLE="Dates" ID="dates"> |
- <P> |
- ISO 8601 defines date and time formats. Some benefits include: |
- </P> |
- <LIST TYPE="UL"> |
- <LI>language-independent and unambiguous world-wide</LI> |
- <LI>sortable with a trivial string comparison</LI> |
- <LI>easily readable and writable by software</LI> |
- <LI>compatible with standards ISO 9075 and <URL LINKTEXT="rfc 3339">http://www.ietf.org/rfc/rfc3339.txt</URL></LI> |
- </LIST> |
- <P> |
- The ISO Extended format for common date is <ICODE>YYYY-MM-DD</ICODE>, and for time is |
- <ICODE>hh:mm:ss</ICODE>. |
- </P> |
- <P> |
- For an event with an offset from UTC, use <ICODE>YYYY-MM-DDThh:mm:ss±hh:mm</ICODE>. |
- </P> |
- <P> |
- Never use a local date/time format for a non-local event. Instead, use |
- UTC, as in <ICODE>YYYY-MM-DDThh:mm:ssZ</ICODE> (<ICODE>Z</ICODE> is the only letter suffix). |
- </P> |
- <P> |
- The <ICODE>T</ICODE> can be omitted where that would not cause ambiguity. For |
- rfc 3339 compliance, it may be replaced by a space and for SQL, |
- it <EM>must</EM> be replaced by a single space. |
- </P> |
- <P> |
- Year <ICODE>0000</ICODE> is unrecognized by some formats (XML Schema, <ICODE>xs:date</ICODE>). |
- </P> |
- <MOREINFO> |
- <URL LINKTEXT="ECMA-262 Date.prototype, s. 15.9">#onlineResources</URL> |
- <URL LINKTEXT="A summary of the international standard date and time notation, by Markus Kuhn" |
- >http://www.cl.cam.ac.uk/~mgk25/iso-time.html</URL> |
- <URL>http://en.wikipedia.org/wiki/ISO_8601</URL> |
- <URL LINKTEXT="ISO 8601:2004(E)">res/ISO_8601-2004_E.pdf</URL> |
- <URL LINKTEXT="W3C QA Tip: Use international date format (ISO)">http://www.w3.org/QA/Tips/iso-date</URL> |
- <URL LINKTEXT="RFC 3339, Date and Time on the Internet: Timestamps" |
- >http://www.ietf.org/rfc/rfc3339.txt</URL> |
- <URL>http://www.w3.org/TR/xmlschema-2/#dateTime</URL> |
- </MOREINFO> |
- |
- <CONTENT TITLE="How do I format a Date object with javascript?" ID="formatDate" NUMID="4_30"> |
- <P> |
- A local <ICODE>Date</ICODE> object where <ICODE>0 <= year <= 9999</ICODE> can be |
- formatted to a common ISO 8601 format <ICODE>YYYY-MM-DD</ICODE> with:- |
- </P> |
- <CODE> |
-/** Formats a Date to YYYY-MM-DD (local time), compatible with both |
- * ISO 8601 and ISO/IEC 9075-2:2003 (E) (SQL 'date' type). |
- * @param {Date} dateInRange year 0000 to 9999. |
- * @throws {RangeError} if the year is not in range |
- */ |
-function formatDate(dateInRange) { |
- var year = dateInRange.getFullYear(), |
- isInRange = year >= 0 && year <= 9999, yyyy, mm, dd; |
- if(!isInRange) { |
- throw RangeError("formatDate: year must be 0000-9999"); |
- } |
- yyyy = ("000" + year).slice(-4); |
- mm = ("0" + (dateInRange.getMonth() + 1)).slice(-2); |
- dd = ("0" + (dateInRange.getDate())).slice(-2); |
- return yyyy + "-" + mm + "-" + dd; |
-} |
- </CODE> |
- <MOREINFO> |
- <URL>http://www.merlyn.demon.co.uk/js-date9.htm</URL> |
- </MOREINFO> |
- </CONTENT> |
- <CONTENT TITLE="How can I create a Date object from a String?" ID="parseDate"> |
- <P> |
- An Extended ISO 8601 local Date format <ICODE>YYYY-MM-DD</ICODE> can be parsed to a |
- Date with the following: |
- </P> |
- <CODE> |
-/**Parses string formatted as YYYY-MM-DD to a Date object. |
- * If the supplied string does not match the format, an |
- * invalid Date (value NaN) is returned. |
- * @param {string} dateStringInRange format YYYY-MM-DD, with year in |
- * range of 0000-9999, inclusive. |
- * @return {Date} Date object representing the string. |
- */ |
-function parseISO8601(dateStringInRange) { |
- var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/, |
- date = new Date(NaN), month, |
- parts = isoExp.exec(dateStringInRange); |
- |
- if(parts) { |
- month = +parts[2]; |
- date.setFullYear(parts[1], month - 1, parts[3]); |
- if(month != date.getMonth() + 1) { |
- date.setTime(NaN); |
- } |
- } |
- return date; |
-} |
- </CODE> |
- </CONTENT> |
-</CONTENT> |
\ No newline at end of file |
/cljs/sections/dates.xml |
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/index.xml |
=================================================================== |
--- cljs/index.xml (revision 25) |
+++ cljs/index.xml (revision 24) |
@@ -1,37 +1,2134 @@ |
<!DOCTYPE FAQ [ |
<!ENTITY trade "™"><!-- trade mark sign, U+2122 ISOnum --> |
- |
- <!ENTITY meta SYSTEM "sections/meta.xml"> |
- <!ENTITY overview SYSTEM "sections/overview.xml"> |
- <!ENTITY resources SYSTEM "sections/resources.xml"> |
- <!ENTITY functions SYSTEM "sections/functions.xml"> |
- <!ENTITY dates SYSTEM "sections/dates.xml"> |
- <!ENTITY numbers SYSTEM "sections/numbers.xml"> |
- <!ENTITY objects SYSTEM "sections/objects.xml"> |
- <!ENTITY strings SYSTEM "sections/strings.xml"> |
- <!ENTITY dom SYSTEM "sections/dom.xml"> |
- <!ENTITY windows SYSTEM "sections/windows.xml"> |
- <!ENTITY server SYSTEM "sections/server.xml"> |
- <!ENTITY debugging SYSTEM "sections/debugging.xml"> |
- <!ENTITY donts SYSTEM "sections/donts.xml"> |
- <!ENTITY suggestions SYSTEM "sections/suggestions.xml"> |
]> |
<FAQ VERSION="32.2" DATE="2010-10-08" revision="$Revision$" id="$Id$"> |
<TITLE>FAQ for comp.lang.javascript</TITLE> |
<CONTENTS> |
- &meta; |
- &overview; |
- &resources; |
- &functions; |
- &dates; |
- &numbers; |
- &objects; |
- &strings; |
- &dom; |
- &windows; |
- &server; |
- &debugging; |
- &donts; |
- &suggestions; |
+ <CONTENT TITLE="Meta-FAQ meta-questions" ID="meta" NUMID="1"> |
+ <P> |
+ This is the <EM>comp.lang.javascript</EM> meta-FAQ, <VER/>. The latest |
+ version is available at <URL>http://jibbering.com/faq/</URL> in HTML form. |
+ </P> |
+ <P> |
+ Each day, one section of the FAQ is posted for review and questions, |
+ and as a reminder that the FAQ is available. |
+ </P> |
+ <P> |
+ For additional explanation and detail relating to some aspects |
+ of the FAQ, please see the |
+ <URL LINKTEXT="FAQ Notes">notes/</URL>. |
+ It has been provided separately to avoid increasing the size of |
+ the FAQ to a point where it would be unreasonable to post it to |
+ the group. |
+ </P> |
+ <P> |
+ Code examples in this FAQ use <URL LINKTEXT="JSDoc Toolkit" |
+ >http://jsdoctoolkit.org/</URL> comments. |
+ </P> |
+ |
+ <CONTENT TITLE="Which newsgroups deal with javascript?" ID="newsgroups" NUMID="2_1"> |
+ <P> |
+ The official Big 8 Usenet newsgroup dealing with javascript is |
+ <NEWSGROUP>comp.lang.javascript</NEWSGROUP>. |
+ Some "language" hierarchies also have *.comp.lang.javascript groups. |
+ </P> |
+ <P> |
+ c.l.js is an unmoderated newsgroup. |
+ </P> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="What questions are on-topic for comp.lang.javascript?" ID="appropriateQuestions" NUMID="2_2"> |
+ <P> |
+ The comp.lang.javascript newsgroup deals with ECMAScript |
+ languages, so any questions about JavaScript or JScript are |
+ welcome. However, the majority of questions sent to this group |
+ relates to javascript in a web browser. If you are experiencing |
+ issues with a particular browser, or the host is not a browser |
+ at all, please make this information clear. |
+ </P> |
+ <P> |
+ 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 c.l.js (as Java and |
+ javascript are distinct programming languages with only |
+ superficial similarities due to sharing a C-like syntax and |
+ some of the characters in their names). |
+ </P> |
+ <P> |
+ Questions dealing with other scripting languages, such as |
+ VBScript, PerlScript or CGI scripting are also off-topic, |
+ as are HTML-only or CSS-only questions. |
+ </P> |
+ <!-- |
+ <P> |
+ Questions about the design of various javascript libraries are |
+ appropriate; questions on how to <EM>use</EM> such libraries |
+ are not. Check <URL LINKTEXT="c.l.js FAQ Resources" |
+ >http://jibbering.comindex.html#libraryResources</URL> or search the web. |
+ </P> |
+ --> |
+ <P> |
+ Questions that are specific to Microsoft's JScript may also |
+ be appropriately asked at: |
+ <NEWSGROUP>microsoft.public.scripting.jscript</NEWSGROUP> |
+ </P> |
+ <P> |
+ The comp.lang.javascript newsgroup charter is included in |
+ <URL>faq_notes/cljs_charter.html</URL>. |
+ </P> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="What should I do before posting to comp.lang.javascript?" ID="posting" NUMID="2_3"> |
+ <P> |
+ Before posting to c.l.js, you should read this document. |
+ You should also check the <URL LINKTEXT="Resources section">#onlineResources</URL>. |
+ </P> |
+ <LIST TYPE="UL" TITLE="How to Ask a Question" ID="ask"> |
+ <LI>State your question clearly and concisely.</LI> |
+ <LI>Use the Subject: line to show the type of problem you have but |
+ include the question in the body as well.</LI> |
+ <LI>For a more detailed explanation of formatting, see |
+ "<URL LINKTEXT="Posting Questions and Replies to comp.lang.javascript">notes/posting/</URL>".</LI> |
+ </LIST> |
+ |
+ <LIST TYPE="UL" TITLE="Replying" ID="reply"> |
+ <LI>Quote only relevant parts of earlier messages, and add your |
+ comments below each quoted section |
+ (<URL LINKTEXT="FYI28/RFC1855">http://www.ietf.org/rfc/rfc1855.txt</URL>).</LI> |
+ <LI>Link to specific sections of the FAQ that are relevant.</LI> |
+ <LI>Avoid being unnecessarily rude, but do not complain about other rude posts.</LI> |
+ <LI>Don't quote signatures.</LI> |
+ </LIST> |
+ |
+ <LIST TYPE="UL" TITLE="Posting Code" ID="postCode"> |
+ <LI> |
+ Remove everything that does not contribute to the problem (images, |
+ markup, other scripts, etc). |
+ </LI> |
+ <LI>Validate the HTML and CSS <URL>http://validator.w3.org/</URL>, |
+ <URL>http://jigsaw.w3.org/css-validator/</URL>.</LI> |
+ <LI>Make sure the code is executable as transmitted.</LI> |
+ <LI>Format lines to 72 characters; indent with 2-4 spaces (not tabs).</LI> |
+ <LI>State what you expect the code to do.</LI> |
+ <LI>Mention the platforms, browsers, and versions.</LI> |
+ <LI>See also the <URL LINKTEXT="FAQ section on debugging">#debugging</URL>.</LI> |
+ <LI>Post in plain-text only. Do not encode it. Do not attach files.</LI> |
+ <LI>If the code is more than about 100 lines, provide a URL in addition.</LI> |
+ <LI>Do not multi-post; cross-post if necessary |
+ (<URL LINKTEXT="Wikipedia description">http://en.wikipedia.org/wiki/Cross-post</URL>).</LI> |
+ </LIST> |
+ <LIST TYPE="UL" TITLE="What Not to Post" ID="doNotPost"> |
+ <LI>Do not post job postings. Job postings should go to |
+ an appropriate regional jobs group.</LI> |
+ <LI>Do not post copyright material without permission |
+ from the copyright holder.</LI> |
+ </LIST> |
+ <P> |
+ Relevant announcements are welcome, but no more often than once |
+ per major release, as a short link to the product's webpage. |
+ </P> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Why was my post not answered?" ID="noAnswer" NUMID="2_4"> |
+ <P>This could be for several reasons:</P> |
+ <UL> |
+ <LI>It was a variation of a frequently asked question and was |
+ therefore ignored by everyone.</LI> |
+ <LI>Nobody knows the answer.</LI> |
+ <LI>The person with the answer has not seen the post.</LI> |
+ <LI>It might not be possible to do what you want to do but perhaps |
+ readers of c.l.js are reluctant to answer your post in the negative |
+ when they are not convinced that it cannot be done.</LI> |
+ <LI>The question was not asked clearly enough, or did not included |
+ enough information to be answered.</LI> |
+ <LI>The questioner did not realise the need to read the group, for a |
+ few days, to see the answers posted there.</LI> |
+ <LI>You ignored the <URL LINKTEXT="section on posting">#posting</URL></LI> |
+ </UL> |
+ |
+ <p>If it is not one of these, then after a few days consider |
+ reposting after checking |
+ <URL>http://groups.google.com/group/comp.lang.javascript/topics</URL> |
+ for replies. Make sure the post is phrased well, and everything |
+ needed to answer is correct, and the subject is appropriate.</p> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Language Overview" ID="tips" NUMID="2"> |
+ <CONTENT TITLE="What is ECMAScript?" ID="ecma" NUMID="2_6"> |
+ <P> |
+ <URL LINKTEXT="ECMA-262">http://www.ecma-international.org/publications/standards/Ecma-262.htm</URL> |
+ is the international standard that current language implementations |
+ (JavaScript™, JScript etc.) are based on. |
+ </P> |
+ <P> |
+ <URL LINKTEXT="ECMA-262">http://www.ecma-international.org/publications/standards/Ecma-262.htm</URL> |
+ defines the language Syntax, Types, Keywords, Operators, and built-in |
+ objects. The ECMAScript specification is the reference to determine the |
+ expected behavior of a program. ECMAScript does not define any host |
+ objects, such as <ICODE>document</ICODE>, <ICODE>window</ICODE>, or |
+ <ICODE>ActiveXObject</ICODE>. |
+ </P> |
+ <P> |
+ ECMA-327 defines the Compact Profile of ECMAScript by |
+ describing the features from ECMA 262 that may be omitted in some |
+ resource-constrained environments. |
+ <URL>http://www.ecma-international.org/publications/standards/Ecma-327.htm</URL> |
+ </P> |
+ <P> |
+ The most widely supported edition of ECMA-262 is the 3rd edition (1999). |
+ There is fair support for this edition in JScript 5.5+ (buggy) and good |
+ support JavaScript 1.5. |
+ </P> |
+ <P> |
+ The term "javascript" is used as a common name for all dialects of ECMAScript. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="What is JScript?" ID="jScript" NUMID="2_7"> |
+ <P> |
+ JScript is Microsoft's implementation of ECMAScript. |
+ </P> |
+ <P> |
+ Questions that are specific to Microsoft's JScript may also |
+ be appropriately asked at: |
+ <NEWSGROUP>microsoft.public.scripting.jscript</NEWSGROUP>. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="What is the Document Object Model (DOM)?" ID="dom" NUMID="2_9"> |
+ <P> |
+ The <DFN>Document Object Model</DFN> (DOM) is a interface-based model for <ICODE>Document</ICODE> |
+ objects. The DOM allows scripts to dynamically access and update a |
+ document's content, style, and event handlers. |
+ </P> |
+ <P> |
+ The DOM is <EM>not</EM> part of the ECMAScript programming language. |
+ </P> |
+ <P> |
+ Official DOM standards are defined by the World Wide Web Consortium. |
+ Scriptable browsers also have <DFN>proprietary</DFN> DOM features (<URL |
+ LINKTEXT="MSDN">http://msdn.microsoft.com/en-us/library/ms533050(VS.85).aspx</URL>, <URL |
+ LINKTEXT="MDC">https://developer.mozilla.org/en/DOM_Client_Object_Cross-Reference</URL>), |
+ such as <ICODE>document.writeln()</ICODE>. |
+ </P> |
+ <P> |
+ Also see the section on <URL LINKTEXT="DOM and Forms">#domRef</URL>. |
+ </P> |
+ <MOREINFO> |
+ <URL LINKTEXT="c.l.js DOM Resources">#onlineResources</URL> |
+ <URL LINKTEXT="W3C DOM FAQ">http://www.w3.org/DOM/faq.html</URL> |
+ <URL LINKTEXT="W3C DOM ">http://www.w3.org/DOM/</URL> |
+ <URL LINKTEXT="MDC: What is the DOM?">https://developer.mozilla.org/en/Gecko_DOM_Reference/Introduction#What_is_the_DOM.3F</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="Internationalisation and Localisation in javascript" ID="localization" NUMID="2_10"> |
+ <P> |
+ <DFN>Internationalisation</DFN> means using one form which is everywhere both |
+ acceptable and understood. Any international standard not supported by |
+ default can be coded for. |
+ </P> |
+ <P> |
+ For example, there is an International Standard for numeric Gregorian |
+ date format; but none for decimal and thousands separators. |
+ </P> |
+ <P> |
+ <DFN>Localisation</DFN> is the process of adapting software for a specific region |
+ or language by adding locale-specific components and translating text. It |
+ cannot work well in general, because it requires a knowledge of all |
+ preferences and the ability to choose the right one, in an environment |
+ where many systems are inappropriately set anyway. |
+ </P> |
+ <P> |
+ ECMAScript has a few <DFN>localisation</DFN> features. The various |
+ <ICODE>toString()</ICODE> methods are all implementation dependent, |
+ but tend to use either UK or US settings (not necessarily correctly). |
+ ECMAScript Ed. 3 introduced some capabilities, including the |
+ <ICODE>toLocaleString()</ICODE>method which should create a string |
+ based on the host's locale. |
+ </P> |
+ <P> |
+ ECMAScript 5th Edition introduces limited ISO 8601 capabilities with |
+ <ICODE>Date.prototype.toISOString()</ICODE> and new behavior for <ICODE>Date.parse()</ICODE>. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="What does the future hold for ECMAScript?" ID="futureEcmaScript" NUMID="2_12"> |
+ <P> |
+ The 5th edition of ECMAScript was approved on 2009-12-04. There is some |
+ support in implementations released before approval date (JScript 5.8, |
+ JavaScript 1.8, JavaScriptCore). |
+ http://www.ecma-international.org/publications/standards/Ecma-262.htm |
+ </P> |
+ <MOREINFO> |
+ <URL>http://www.ecma-international.org/publications/standards/Ecma-262.htm</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Javascript Resources" ID="ecmascriptResources" NUMID="3"> |
+ <CONTENT TITLE="What books are recommended for javascript?" ID="books" NUMID="3_1"> |
+ <P> |
+ Most javascript books have been found to contain so many technical |
+ errors that consensus recommendations have not emerged from the group. |
+ </P> |
+ <P> |
+ The following books have been considered to have value by some |
+ individuals on c.l.js. The reviews of these books are provided: |
+ </P> |
+ <LIST TYPE="UL"> |
+ <LI><EM>"JavaScript: The Definitive Guide,"</EM> 5th Edition, by David Flanagan |
+ <UL> |
+ <LI>Published: 2006-08</LI> |
+ <LI>Pages: 1018</LI> |
+ <LI>Errata: <URL>http://oreilly.com/catalog/9780596101992/errata/</URL></LI> |
+ <LI>Discussed in: |
+ <UL> |
+ <LI> |
+ <URL LINKTEXT="FAQ Update 9.85 Dated 2007-08-31" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/7283898f77fd2a66/9252aa024e058dea#c5f145ae807c918e</URL> |
+ </LI> |
+ </UL> |
+ </LI> |
+ </UL> |
+ </LI> |
+ <LI> |
+ <EM>"JavaScript, The Good Parts,"</EM> 1st Edition, by Douglas Crockford |
+ <UL> |
+ <LI>Published: 2008-05</LI> |
+ <LI>Pages: 170</LI> |
+ <LI>Errata: <URL>http://oreilly.com/catalog/9780596517748/errata/</URL></LI> |
+ <LI>Discussed in: |
+ <UL> |
+ <LI> |
+ <URL LINKTEXT="Crockford's 'The Good Parts': a short review" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/d084d2109f7b4ec7#</URL> |
+ </LI> |
+ <LI> |
+ <URL LINKTEXT="FunctionExpression's and memory consumptions" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/db1e49ab113aa05c/3987eac87ad27966#3987eac87ad27966</URL> |
+ </LI> |
+ <LI> |
+ <URL LINKTEXT="FAQ Topic - What books are recommended for javascript? (2008-12-02)" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/6a41f7835ee728de/da5ccfc65e2df64a#da5ccfc65e2df64a</URL> |
+ </LI> |
+ <LI> |
+ <URL LINKTEXT="Augmenting functions" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/3a08fb741525ab6d/</URL> |
+ </LI> |
+ |
+ <LI> |
+ <URL LINKTEXT="Crockford's JavaScript, The Good Parts (a book review)." |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/bf26be6e63494ee2/acb733a1c35f6ce5#ee9e4ee29e658d5d</URL> |
+ </LI> |
+ <LI> |
+ <URL LINKTEXT="Closures Explained" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/df602506ee48b400/e65e00f5cad07676#e65e00f5cad07676</URL> |
+ </LI> |
+ <LI> |
+ <URL LINKTEXT="Javascript library development" |
+ >http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/acadf1b22b219433/4f69a95607d0b3ae#4f69a95607d0b3ae</URL> |
+ </LI> |
+ </UL></LI> |
+ </UL> |
+ </LI> |
+ </LIST> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="What online resources are available?" ID="onlineResources" NUMID="3_2"> |
+ <LIST TITLE="ECMAScript" TYPE="DL" ID="ecmaResources"> |
+ <DT>The Official ECMAScript Specification</DT> |
+ <DD><URL>[ECMA-262] http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm</URL></DD> |
+ |
+ <DT>[ISO16262] ISO/IEC 16262, Second Edition 2002-06-01 : ISO Standard matching |
+ ECMA-262 3rd Edition, with corrections.</DT> |
+ <DD><URL>http://standards.iso.org/ittf/PubliclyAvailableStandards/c033835_ISO_IEC_16262_2002(E).zip</URL></DD> |
+ |
+ <DT>[MS-ES3]: Internet Explorer ECMA-262 ECMAScript Language Specification Standards Support</DT> |
+ <DD><URL>http://msdn.microsoft.com/en-us/library/ff520996%28VS.85%29.aspx</URL></DD> |
+ <DD><URL>res/%5BMS-ES3%5D.pdf</URL> (local alias)</DD> |
+ |
+ <DT>[MS-ES3EX]: Microsoft JScript Extensions to the ECMAScript Language Specification Third Edition</DT> |
+ <DD><URL>http://msdn.microsoft.com/en-us/library/ff521046%28VS.85%29.aspx</URL></DD> |
+ <DD><URL>res/%5BMS-ES3EX%5D.pdf</URL> (local alias)</DD> |
+ |
+ <DT>ECMAScript on Wikipedia</DT> |
+ <DD><URL>http://en.wikipedia.org/wiki/ECMAScript</URL></DD> |
+ </LIST> |
+ |
+ <LIST TITLE="W3C DOM" TYPE="DL" ID="domResources"> |
+ <DT>DOM Level 1 ECMAScript Binding</DT> |
+ <DD><URL>http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html</URL></DD> |
+ |
+ <DT>DOM Level 2 ECMAScript Binding</DT> |
+ <DD><URL>http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html</URL></DD> |
+ |
+ <DT>DOM Level 2 Events</DT> |
+ <DD><URL>http://www.w3.org/TR/DOM-Level-2-Events/events.html</URL></DD> |
+ |
+ <DT>DOM Level 2 Style</DT> |
+ <DD><URL>http://www.w3.org/TR/DOM-Level-2-Style/</URL></DD> |
+ |
+ <DT>DOM Level 3 ECMAScript Binding</DT> |
+ <DD><URL>http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html</URL></DD> |
+ </LIST> |
+ |
+ <LIST TITLE="Browser Documentation" TYPE="DL" ID="browserResources"> |
+ <DT>Mozilla</DT> |
+ <DD>JavaScript: <URL>http://developer.mozilla.org/en/docs/JavaScript</URL></DD> |
+ <DD>Gecko DOM Reference: <URL>http://developer.mozilla.org/en/docs/Gecko_DOM_Reference</URL></DD> |
+ |
+ <DT>Microsoft</DT> |
+ <DD>HTML and DHTML Reference: <URL>http://msdn.microsoft.com/en-us/library/ms533050.aspx</URL></DD> |
+ <DD>JScript Language Reference:<URL>http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx</URL></DD> |
+ <DD>Scripting: <URL>http://msdn.microsoft.com/en-us/library/ms950396.aspx</URL></DD> |
+ |
+ <DT>Opera</DT> |
+ <DD>Web Specifications Support: <URL>http://www.opera.com/docs/specs/#ecmascript</URL></DD> |
+ |
+ <DD>JavaScript Support: <URL>http://www.opera.com/docs/specs/js/</URL></DD> |
+ <DD>ECMAScript Support: <URL>http://www.opera.com/docs/specs/js/ecma</URL></DD> |
+ |
+ <DT>BlackBerry JavaScript Reference</DT> |
+ <DD><URL>http://docs.blackberry.com/en/developers/deliverables/11849/</URL></DD> |
+ |
+ <DT>ICab InScript</DT> |
+ <DD><URL>http://www.muchsoft.com/inscript/</URL></DD> |
+ |
+ <DT>Apple Safari</DT> |
+ <DD>Web Content Guide: <URL>http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html</URL></DD> |
+ |
+ <DT>Webkit</DT> |
+ <DD>Project Site: <URL>http://webkit.org/</URL></DD> |
+ <DD>Wiki: <URL>http://trac.webkit.org/wiki</URL></DD> |
+ <DD>DOM Reference: <URL>http://developer.apple.com/Mac/library/documentation/AppleApplications/Reference/WebKitDOMRef/index.html#//apple_ref/doc/uid/TP40006089</URL></DD> |
+ |
+ <DT>Netscape 4 Client-Side JavaScript Reference</DT> |
+ <DD><URL>http://docs.sun.com/source/816-6408-10/</URL></DD> |
+ |
+ <DT>Archived documentation for MSIE 3.x</DT> |
+ <DD><URL>http://members.tripod.com/%7Ehousten/download/</URL></DD> |
+ </LIST> |
+ |
+ <LIST TITLE="Standalone ECMAScript Implementations" TYPE="DL" ID="standaloneImplementations"> |
+ <DT>Rhino: An open-source implementation of JavaScript written in Java</DT> |
+ <DD><URL>http://www.mozilla.org/rhino/</URL></DD> |
+ |
+ <DT>Besen IDE: ECMAScript Edition 5 with IDE</DT> |
+ <DD><URL>http://besen.sourceforge.net/</URL></DD> |
+ |
+ <DT>V8: Google's open source JavaScript engine</DT> |
+ <DD><URL>http://code.google.com/p/v8/</URL></DD> |
+ |
+ <DT>SpiderMonkey: Mozilla's C implementation of JavaScript</DT> |
+ <DD><URL>http://www.mozilla.org/js/spidermonkey/</URL></DD> |
+ |
+ <DT>Digital Mars DMD Script, console and MS Active Script implementation of ECMAScript</DT> |
+ <DD><URL>http://www.digitalmars.com/dscript/</URL></DD> |
+ </LIST> |
+ |
+ <LIST TITLE="Other ECMAScript Implementations" TYPE="DL" ID="nonBrowserResources"> |
+ <DT>Developing Dashboard Widgets: Apple Developer Connection</DT> |
+ <DD><URL>http://developer.apple.com/macosx/dashboard.html</URL></DD> |
+ |
+ <DT>Whitebeam Apache Module: Server Side JavaScript in Apache</DT> |
+ <DD><URL>http://www.whitebeam.org/</URL></DD> |
+ </LIST> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Javascript Libraries" ID="libraryResources"> |
+ <P> |
+ No javascript libraries are endorsed by this group. If you want help |
+ with using a library, visit that library's discussion group instead. |
+ </P> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Functions" ID="functions"> |
+ <CONTENT TITLE="What is (function(){ /*...*/ })() ?" ID="scope"> |
+ <P> |
+ This is an anonymous <DFN>FunctionExpression</DFN> that is called |
+ immediately after creation. |
+ </P> |
+ <P> |
+ Variables declared inside a function are not accessible from |
+ outside the function. This can be useful, for example, to hide |
+ implementation details or to avoid polluting the global scope. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://yura.thinkweb2.com/named-function-expressions/</URL> |
+ <URL>notes/closures/</URL> |
+ <URL>http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="What is a function statement?" ID="functionStatement"> |
+ <P> |
+ The term <DFN>function statement</DFN> has been widely and wrongly used to |
+ describe a <ICODE>FunctionDeclaration</ICODE>. This is misleading because in ECMAScript, |
+ a <ICODE>FunctionDeclaration</ICODE> is not a <DFN>Statement</DFN>; there are places in a program |
+ where a <DFN>Statement</DFN> is permitted but a <ICODE>FunctionDeclaration</ICODE> is not. To add |
+ to this confusion, some implementations, notably Mozillas', provide a |
+ syntax extension called <DFN>function statement</DFN>. This is allowed under |
+ section 16 of ECMA-262, Editions 3 and 5. |
+ </P> |
+ <P> |
+ Example of nonstandard <DFN>function statement</DFN>: |
+ </P> |
+ <CODE> |
+ // Nonstandard syntax, found in GMail source code. DO NOT USE. |
+ try { |
+ // FunctionDeclaration not allowed in Block. |
+ function Fze(b,a){return b.unselectable=a} |
+ /*...*/ |
+ } catch(e) { _DumpException(e) } |
+ </CODE> |
+ <P> |
+ Code that uses <DFN>function statement</DFN> has three known interpretations. Some |
+ implementations process <ICODE>Fze</ICODE> as a <DFN>Statement</DFN>, in order. Others, including |
+ JScript, evaluate <ICODE>Fze</ICODE> upon entering the execution context that it |
+ appears in. Yet others, notably DMDScript and default configuration of BESEN, |
+ throw a <ICODE>SyntaxError</ICODE>. |
+ </P> |
+ <P> |
+ For consistent behavior across implementations, <EM>do not use function |
+ statement</EM>; use either <ICODE>FunctionExpression</ICODE> or <ICODE>FunctionDeclaration</ICODE> instead. |
+ </P> |
+ <P> |
+ Example of <ICODE>FunctionExpression</ICODE> (valid): |
+ </P> |
+ <CODE> |
+var Fze; |
+try { |
+ Fze = function(b,a){return b.unselectable=a}; |
+ /*...*/ |
+} catch(e) { _DumpException(e) } |
+ </CODE> |
+ Example of <ICODE>FunctionDeclaration</ICODE> (valid): |
+ <CODE> |
+// Program code |
+function aa(b,a){return b.unselectable=a} |
+ </CODE> |
+<!-- |
+Notable examples of the misuse of the term "function statement" |
+can be seen in David Flanagan's "JavaScript: The Definitive Guide", |
+Douglas Crockford's "JavaScript: The Good Parts", MDC documentation, |
+JSLint error messages. |
+--> |
+ <MOREINFO> |
+ <URL>example/functionStatement.html</URL> |
+ <URL>https://mail.mozilla.org/pipermail/es-discuss/2008-February/005314.html</URL> |
+ <URL>http://groups.google.com/group/comp.lang.javascript/msg/aa9a32d0c6ae0342</URL> |
+ <URL>http://groups.google.com/group/comp.lang.javascript/msg/3987eac87ad27966</URL> |
+ <URL>http://nanto.asablo.jp/blog/2005/12/10/172622</URL> (Article in Japanese) |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Dates" ID="dates"> |
+ <P> |
+ ISO 8601 defines date and time formats. Some benefits include: |
+ </P> |
+ <LIST TYPE="UL"> |
+ <LI>language-independent and unambiguous world-wide</LI> |
+ <LI>sortable with a trivial string comparison</LI> |
+ <LI>easily readable and writable by software</LI> |
+ <LI>compatible with standards ISO 9075 and <URL LINKTEXT="rfc 3339">http://www.ietf.org/rfc/rfc3339.txt</URL></LI> |
+ </LIST> |
+ <P> |
+ The ISO Extended format for common date is <ICODE>YYYY-MM-DD</ICODE>, and for time is |
+ <ICODE>hh:mm:ss</ICODE>. |
+ </P> |
+ <P> |
+ For an event with an offset from UTC, use <ICODE>YYYY-MM-DDThh:mm:ss±hh:mm</ICODE>. |
+ </P> |
+ <P> |
+ Never use a local date/time format for a non-local event. Instead, use |
+ UTC, as in <ICODE>YYYY-MM-DDThh:mm:ssZ</ICODE> (<ICODE>Z</ICODE> is the only letter suffix). |
+ </P> |
+ <P> |
+ The <ICODE>T</ICODE> can be omitted where that would not cause ambiguity. For |
+ rfc 3339 compliance, it may be replaced by a space and for SQL, |
+ it <EM>must</EM> be replaced by a single space. |
+ </P> |
+ <P> |
+ Year <ICODE>0000</ICODE> is unrecognized by some formats (XML Schema, <ICODE>xs:date</ICODE>). |
+ </P> |
+ <MOREINFO> |
+ <URL LINKTEXT="ECMA-262 Date.prototype, s. 15.9">#onlineResources</URL> |
+ <URL LINKTEXT="A summary of the international standard date and time notation, by Markus Kuhn" |
+ >http://www.cl.cam.ac.uk/~mgk25/iso-time.html</URL> |
+ <URL>http://en.wikipedia.org/wiki/ISO_8601</URL> |
+ <URL LINKTEXT="ISO 8601:2004(E)">res/ISO_8601-2004_E.pdf</URL> |
+ <URL LINKTEXT="W3C QA Tip: Use international date format (ISO)">http://www.w3.org/QA/Tips/iso-date</URL> |
+ <URL LINKTEXT="RFC 3339, Date and Time on the Internet: Timestamps" |
+ >http://www.ietf.org/rfc/rfc3339.txt</URL> |
+ <URL>http://www.w3.org/TR/xmlschema-2/#dateTime</URL> |
+ </MOREINFO> |
+ |
+ <CONTENT TITLE="How do I format a Date object with javascript?" ID="formatDate" NUMID="4_30"> |
+ <P> |
+ A local <ICODE>Date</ICODE> object where <ICODE>0 <= year <= 9999</ICODE> can be |
+ formatted to a common ISO 8601 format <ICODE>YYYY-MM-DD</ICODE> with:- |
+ </P> |
+ <CODE> |
+/** Formats a Date to YYYY-MM-DD (local time), compatible with both |
+ * ISO 8601 and ISO/IEC 9075-2:2003 (E) (SQL 'date' type). |
+ * @param {Date} dateInRange year 0000 to 9999. |
+ * @throws {RangeError} if the year is not in range |
+ */ |
+function formatDate(dateInRange) { |
+ var year = dateInRange.getFullYear(), |
+ isInRange = year >= 0 && year <= 9999, yyyy, mm, dd; |
+ if(!isInRange) { |
+ throw RangeError("formatDate: year must be 0000-9999"); |
+ } |
+ yyyy = ("000" + year).slice(-4); |
+ mm = ("0" + (dateInRange.getMonth() + 1)).slice(-2); |
+ dd = ("0" + (dateInRange.getDate())).slice(-2); |
+ return yyyy + "-" + mm + "-" + dd; |
+} |
+ </CODE> |
+ <MOREINFO> |
+ <URL>http://www.merlyn.demon.co.uk/js-date9.htm</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How can I create a Date object from a String?" ID="parseDate"> |
+ <P> |
+ An Extended ISO 8601 local Date format <ICODE>YYYY-MM-DD</ICODE> can be parsed to a |
+ Date with the following: |
+ </P> |
+ <CODE> |
+/**Parses string formatted as YYYY-MM-DD to a Date object. |
+ * If the supplied string does not match the format, an |
+ * invalid Date (value NaN) is returned. |
+ * @param {string} dateStringInRange format YYYY-MM-DD, with year in |
+ * range of 0000-9999, inclusive. |
+ * @return {Date} Date object representing the string. |
+ */ |
+function parseISO8601(dateStringInRange) { |
+ var isoExp = /^\s*(\d{4})-(\d\d)-(\d\d)\s*$/, |
+ date = new Date(NaN), month, |
+ parts = isoExp.exec(dateStringInRange); |
+ |
+ if(parts) { |
+ month = +parts[2]; |
+ date.setFullYear(parts[1], month - 1, parts[3]); |
+ if(month != date.getMonth() + 1) { |
+ date.setTime(NaN); |
+ } |
+ } |
+ return date; |
+}</CODE> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Numbers" ID="numbers"> |
+ <CONTENT TITLE="How do I format a Number as a String with exactly 2 decimal places?" ID="formatNumber" NUMID="4_6"> |
+ <P> |
+ When formatting money for example, to format 6.57634 to 6.58, 6.7 to |
+ 6.50, and 6 to 6.00? |
+ </P> |
+ <P> |
+ Rounding of x.xx5 is unreliable, as most numbers are not represented |
+ exactly. See also: |
+ <URL LINKTEXT="Why does simple decimal arithmetic give strange results?">#binaryNumbers</URL> |
+ </P> |
+ <P> |
+ The statement <ICODE>n = Math.round(n * 100)/100</ICODE> converts <ICODE>n</ICODE> to a <ICODE>Number</ICODE> value |
+ close to a multiple of <ICODE>0.01</ICODE>. However, there are some problems. |
+ Converting the number to a string <ICODE>(n + "")</ICODE>, does not give |
+ trailing zeroes. Rounding numbers that are very close to <ICODE>x.5</ICODE>, for example, |
+ <ICODE>Math.round(0.49999999999999992)</ICODE> results <ICODE>1</ICODE>. |
+ </P> |
+ <P> |
+ ECMA-262 3rd Edition introduced <ICODE>Number.prototype.toFixed</ICODE>. |
+ There are bugs in JScript 5.8 and below with certain numbers, for example |
+ <ICODE>0.007.toFixed(2)</ICODE> incorrectly results <ICODE>0.00</ICODE>. |
+ </P> |
+ <CODE> |
+var numberToFixed = |
+(function() { |
+ return toFixedString; |
+ |
+ function toFixedString(n, digits) { |
+ var unsigned = toUnsignedString(Math.abs(n), digits); |
+ return (n < 0 ? "-" : "") + unsigned; |
+ } |
+ |
+ function toUnsignedString(m, digits) { |
+ var t, s = Math.round(m * Math.pow(10, digits)) + "", |
+ start, end; |
+ if (/\D/.test(s)) { |
+ return "" + m; |
+ } |
+ s = padLeft(s, 1 + digits, "0"); |
+ start = s.substring(0, t = (s.length - digits)); |
+ end = s.substring(t); |
+ if(end) { |
+ end = "." + end; |
+ } |
+ return start + end; // avoid "0." |
+ } |
+ /** |
+ * @param {string} input: input value converted to string. |
+ * @param {number} size: desired length of output. |
+ * @param {string} ch: single character to prefix to s. |
+ */ |
+ function padLeft(input, size, ch) { |
+ var s = input + ""; |
+ while(s.length < size) { |
+ s = ch + s; |
+ } |
+ return s; |
+ } |
+})(); |
+ |
+// Test results |
+document.writeln([ |
+ "numberToFixed(9e-3, 12) => " + numberToFixed(9e-3, 12), |
+ "numberToFixed(1.255, 2) => " + numberToFixed(1.255, 2), |
+ "numberToFixed(1.355, 2) => " + numberToFixed(1.355, 2), |
+ "numberToFixed(0.1255, 3) => " + numberToFixed(0.1255, 3), |
+ "numberToFixed(0.07, 2) => " + numberToFixed(0.07, 2), |
+ "numberToFixed(0.0000000006, 1) => " + numberToFixed(0.0000000006, 1), |
+ "numberToFixed(0.0000000006, 0) => " + numberToFixed(0.0000000006, 0) |
+].join("\n")); |
+</CODE> |
+ <MOREINFO> |
+ <URL>http://www.merlyn.demon.co.uk/js-round.htm</URL> |
+ <URL>http://msdn.microsoft.com/en-us/library/sstyff0z%28VS.85%29.aspx</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="Why does simple decimal arithmetic give strange results?" ID="binaryNumbers" NUMID="4_7"> |
+ <P> |
+ For example, <ICODE>5 * 1.015</ICODE> does not give exactly |
+ <ICODE>5.075</ICODE> and <ICODE>0.06+0.01</ICODE> does |
+ not give exactly <ICODE>0.07</ICODE> in javascript. |
+ </P> |
+ <P> |
+ ECMAScript numbers are represented in binary as IEEE-754 (IEC 559) |
+ Doubles, with a resolution of 53 bits, giving an accuracy of |
+ 15-16 decimal digits; integers up to just over <ICODE>9e15</ICODE> are |
+ precise, but few decimal fractions are. Given this, arithmetic |
+ is as exact as possible, but no more. Operations on integers |
+ are exact if the true result and all intermediates are integers |
+ within that range. |
+ </P> |
+ <P> |
+ In particular, non-integer results should not normally be |
+ compared for equality; and non-integer computed results |
+ commonly need rounding; see <URL |
+ LINKTEXT="How do I format a Number as a String with exactly 2 decimal places?" |
+ >#formatNumber</URL> |
+ </P> |
+ <MOREINFO> |
+ <URL>http://msdn.microsoft.com/en-us/library/7wkd9z69%28VS.85%29.aspx</URL> |
+ <URL>http://www.merlyn.demon.co.uk/js-misc0.htm#DW4</URL> |
+ </MOREINFO> |
+ <P> |
+ Otherwise, use <ICODE>Math.round</ICODE> on the results of expressions which |
+ should be of integer value. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="Why does K = parseInt('09') set K to 0?" ID="parseIntBase" NUMID="4_12"> |
+ <P> |
+ Method <ICODE>parseInt</ICODE> generally needs a second parameter, <ICODE>radix</ICODE>, |
+ for the base (from 2 to 36). |
+ </P> |
+ <P> |
+ If <ICODE>radix</ICODE> is omitted, the base is determined by the contents of |
+ the string. Any string beginning with <ICODE>'0x'</ICODE> or <ICODE>'0X'</ICODE> represents a |
+ hexadecimal number. A string beginning with a leading 0 may be parsed as |
+ octal (as if <ICODE>raxix</ICODE> were 8), in ECMA-262 Ed 3 (octal digits are <ICODE>0-7</ICODE>). |
+ If string <ICODE>'09'</ICODE> is converted to <ICODE>0</ICODE>. |
+ </P> |
+ <P> |
+ To force use of a particular base, use the <ICODE>radix</ICODE> |
+ parameter: <ICODE>parseInt("09", base)</ICODE>. |
+ |
+ <!-- [omit] |
+ If base 10 is desired, |
+ the unary <ICODE>+</ICODE> operator can be an option. Example: |
+ <ICODE> |
+var s = '-09.1'; // Input string. |
+var j = +s; // Convert to number. Result: -9.1 |
+var n = j|0; // Chop off decimal (convert ToInt32). Result: -9 |
+</ICODE> |
+ [/omit] --> |
+ </P> |
+ <MOREINFO> |
+ <URL>http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt</URL> |
+ <URL>http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx</URL> |
+ <URL>http://docs.sun.com/source/816-6408-10/toplev.htm#1064173</URL> |
+ <URL>notes/type-conversion/#tcPrIntRx</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="Why does 1+1 equal 11? or How do I convert a string to a number?" ID="typeConvert"> |
+ <P> |
+ Variables are not typed; their values are. The conversion between a |
+ string and a number happens automatically. |
+ </P> |
+ <P> |
+ The addition operator (<ICODE>+</ICODE>) performs concatenation if either operand is a |
+ string, thus <ICODE>"1" + 1</ICODE> results <ICODE>"11"</ICODE>. To perform addition, you might need |
+ to first convert the string to a number. For example <ICODE>+varname</ICODE> or |
+ <ICODE>Number(varname)</ICODE> or <ICODE>parseInt(varname, 10)</ICODE> or |
+ <ICODE>parseFloat(varname)</ICODE>. Form control values are strings, as is the result |
+ from a <ICODE>prompt</ICODE> dialog. Convert these to numbers before performing |
+ addition: <ICODE>+'1' + 1</ICODE> results <ICODE>2</ICODE>. |
+ </P> |
+ <MOREINFO> |
+ <URL LINKTEXT="Additional Notes">notes/type-conversion/</URL> |
+ <URL>http://msdn.microsoft.com/en-us/library/67defydd%28VS.85%29.aspx</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I generate a random integer from 1 to n?" ID="randomNumber" NUMID="4_22"> |
+ <P> |
+ <ICODE>Math.random()</ICODE> returns a value <ICODE>R</ICODE> such that <ICODE>0 <= R < 1.0</ICODE>; therefore: |
+ </P> |
+ <CODE> |
+// positive integer expected |
+function getRandomNumber(n) { |
+ return Math.floor(n * Math.random()); |
+} |
+ </CODE> |
+ - gives an evenly distributed random integer in the range from |
+ <ICODE>0</ICODE> to <ICODE>n - 1</ICODE> inclusive; use <ICODE>getRandomNumber(n)+1</ICODE> for <ICODE>1</ICODE> to <ICODE>n</ICODE>. |
+ <MOREINFO> |
+ <URL>http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx</URL> |
+ <URL>http://docs.sun.com/source/816-6408-10/math.htm</URL> |
+How to Deal and Shuffle, see in: <URL>http://www.merlyn.demon.co.uk/js-randm.htm</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Objects" ID="objects"> |
+ <CONTENT TITLE="What is a native object?" ID="nativeObject"> |
+ <P> |
+ A <DFN>native object</DFN> is any object whose semantics are fully defined by |
+ ECMA-262. |
+ </P> |
+ <P> |
+ Some <DFN>native objects</DFN> are <DFN>built-in</DFN>; others, such as <DFN>user-defined</DFN> objects, |
+ may be constructed during the execution of an ECMAScript program. |
+ </P> |
+ <P> |
+ Example: |
+ </P> |
+ <CODE> |
+// Native built-in objects: |
+var m = Math, // Built-in Math object. |
+ slice = Array.prototype.slice, // Built-in native method. |
+ o = {}, // Native user-defined object. |
+ f = function(){}, // Native user-defined function. |
+ d = new Date(), |
+ a = [], |
+ e = new Error("My Message."); |
+ </CODE> |
+ See also: |
+ <MOREINFO> |
+ <URL>http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="What is a built-in object?" ID="builtInObject"> |
+ <P> |
+ A <DFN>built-in</DFN> object is any object supplied by an ECMAScript |
+ implementation, independent of the host environment, that is present |
+ at the start of the execution of an ECMAScript program. |
+ </P> |
+ <P> |
+ECMA-262 3rd Edition defines the following <DFN>built-in</DFN> objects: |
+</P> |
+<LIST TYPE="DL" ID="builtInsList"> |
+ <DT>Objects</DT> |
+ <DD><EM>global</EM>, Math</DD> |
+ |
+ <DT>Constructors</DT> |
+ <DD>Object, Function, Array, String, Boolean, Number, Date, RegExp</DD> |
+ |
+ <DT>Errors</DT> |
+ <DD>Error, Date, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError</DD> |
+ |
+ <DT>Functions</DT> |
+ <DD>eval, parseInt, parseFloat, isNaN, isFinite, decodeURI, |
+ decodeURIComponent, encodeURI, encodeURIComponent</DD> |
+ </LIST> |
+ <P> |
+ECMA-262 Edition 5 defines also the built-in object <ICODE>JSON</ICODE>. |
+</P> |
+<P> |
+Nonstandard <DFN>built-in</DFN> objects may include <ICODE>RuntimeObject</ICODE>, |
+<ICODE>String.prototype.link</ICODE>, <ICODE>CollectGarbage</ICODE>, and more. |
+</P> |
+</CONTENT> |
+ |
+ <CONTENT TITLE="What is a host object?" ID="hostObject" NUMID="2_8"> |
+ <P> |
+A <DFN>host object</DFN> is any object supplied by the host environment to |
+complete the execution environment of ECMAScript. |
+</P> |
+<P> |
+A <DFN>host object</DFN> is not part of the ECMAScript implementation, but is |
+exposed to the ECMAScript implementation. |
+</P> |
+<P> |
+A <DFN>host object</DFN> may be implemented as a native ECMAScript object, however |
+this is not required. For example, Internet Explorer implements many |
+scriptable DOM objects as ActiveX Objects, often resulting in unexpected errors. |
+</P> |
+<P> |
+Availability and behavior of a host object depends on the host environment. |
+</P> |
+<P> |
+For example, in a browser, <ICODE>XMLHttpRequest</ICODE> might be available, with or |
+without standard or proprietary features or events. Windows Script Host object model |
+has the <ICODE>WScript</ICODE> object available. |
+</P> |
+<P> |
+ For information on a particular host object, consult the pertinent |
+ documentation available for the implementation(s). For web browsers, |
+ this usually includes the w3c specifications as well as documentation |
+ for that browser. |
+ See also: |
+</P> |
+ |
+<MOREINFO> |
+<URL>notes/code-guidelines/#hostObjects</URL> |
+<URL>http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="When should I use eval?" ID="eval" NUMID="4_40"> |
+ <P> |
+The <ICODE>eval</ICODE> function should <EM>only</EM> be used when it is necessary to |
+evaluate a string supplied or composed at run-time; the string |
+can be anything from a simple (but unpredictable) expression such |
+as <ICODE>"12 * 2.54"</ICODE> to a substantial piece of javascript code. |
+</P> |
+<P> |
+When <ICODE>eval( '{"key" : 42}' )</ICODE> is called, <ICODE>{</ICODE> is interpreted as a block of |
+code instead of an object literal. Hence, the Grouping Operator (parentheses) |
+is used to force <ICODE>eval</ICODE> to interpret the JSON as an object literal: |
+<ICODE>eval( '({"key" : 42})' );</ICODE>. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://json.org/</URL> |
+ <URL LINKTEXT="How do I access a property of an object using a string?" |
+ >#propertyAccessAgain</URL> |
+ <URL>notes/square-brackets/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I access a property of an object using a string?" ID="propertyAccessAgain" NUMID="4_39"> |
+ <P> |
+There are two ways to access properties: dot notation and square bracket |
+notation. What you are looking for is the square bracket notation in |
+which the dot, and the identifier to its right, are replaced with a set |
+of square brackets containing a string. The value of the string matches |
+the identifier. For example:- |
+ </P> |
+ <CODE> |
+//dot notation |
+var bodyElement = document.body; |
+ |
+//square bracket notation, using an expression |
+var bodyElement = document["bo"+"dy"];</CODE> |
+ <MOREINFO> |
+ <URL>notes/square-brackets/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ <CONTENT TITLE="Strings and RegExp" ID="strings"> |
+ <CONTENT TITLE="How do I trim whitespace?" ID="trimString" NUMID="4_16"> |
+ <P> |
+ ECMAScript 5 defines <ICODE>String.prototype.trim</ICODE>. Where not supported, |
+ it can be added as a function that uses a <DFN>regular expression</DFN>: |
+ </P> |
+ <CODE> |
+if(!String.prototype.trim) { |
+ String.prototype.trim = function() { |
+ return String(this).replace(/^\s+|\s+$/g, ""); |
+ }; |
+} |
+ </CODE> |
+ <P> |
+ Implementations are inconsistent with <ICODE>\s</ICODE>. For example, |
+ some implementations, notably JScript 5.8 and Safari 2, do not match <ICODE>\xA0</ICODE> |
+ (no-break space), among others.</P> |
+ <P> |
+ A more consistent approach would be to create a character class |
+ that defines the characters to trim. |
+ </P> |
+ <MOREINFO> |
+ <URL>https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp</URL> |
+ <URL>http://thinkweb2.com/projects/prototype/whitespace-deviations/</URL> |
+ <URL>https://developer.mozilla.org/en/Firefox_3.1_for_developers</URL> |
+ <URL>http://docs.sun.com/source/816-6408-10/regexp.htm</URL> |
+ <URL>http://msdn.microsoft.com/en-us/library/6wzad2b2%28VS.85%29.aspx</URL> |
+ <URL>http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/c7010139217600c3/31092c5eb99625d0?#31092c5eb99625d0</URL> |
+ <URL>http://unicode.org/Public/UNIDATA/PropList.txt</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="DOM and Forms" ID="domRef"> |
+ <CONTENT TITLE="How do I get the value of a form control?" |
+ ID="formControlAccess" NUMID="4_13"> |
+ <P> |
+ In HTML documents, a form may be referred to as a property of the |
+ <ICODE>document.forms</ICODE> collection, either by its ordinal index or by name |
+ (if the <ICODE>form</ICODE> has a name). A <ICODE>form</ICODE>'s controls may be similarly referenced |
+ from its <ICODE>elements</ICODE> collection: |
+ </P> |
+ <CODE> |
+var frm = document.forms[0]; |
+var control = frm.elements["elementname"]; |
+ </CODE> |
+ <P> |
+ Once a reference to a control is obtained, its (string) <ICODE>value</ICODE> |
+ property can be read:- |
+ </P> |
+ <CODE> |
+var value = control.value; |
+value = +control.value; //string to number. |
+ </CODE> |
+ Some exceptions would be: |
+ <P> |
+ First Exception: Where the control is a <ICODE>SELECT</ICODE> element, and |
+ support for older browsers, such as NN4, is required: |
+ </P> |
+ <CODE> |
+var value = control.options[control.selectedIndex].value; |
+ </CODE> |
+ <P> |
+ Second Exception: Where several controls share the same name, |
+ such as radio buttons. These are made available as collections |
+ and require additional handling. For more information, see:- |
+ </P> |
+ <MOREINFO> |
+ <URL>notes/form-access/</URL> |
+ <URL LINKTEXT="Unsafe Names for HTML Form Controls">names/</URL> |
+ </MOREINFO> |
+ <P> |
+ Third Exception: File inputs. Most current browsers do not allow |
+ reading of <ICODE>type="file"</ICODE> input elements in a way that is useful. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="My element is named myselect[], how do I access it?" ID="propertyAccess" NUMID="4_25"> |
+ <P> |
+Form controls with any "illegal" characters can be accessed with |
+<ICODE>formref.elements["myselect[]"]</ICODE> - The bracket characters, |
+amongst others, are illegal in ID attributes and javascript |
+identifiers, so you should try to avoid them as browsers may |
+handle them incorrectly. |
+ </P> |
+<MOREINFO> |
+<URL>http://msdn.microsoft.com/en-us/library/ms537449%28VS.85%29.aspx</URL> |
+<URL>https://developer.mozilla.org/en/DOM/form</URL> |
+<URL>notes/form-access/</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="Why doesn't the global variable "divId" always refer to the element with id="divId"?" |
+ ID="globalPollution" NUMID="4_41"> |
+ <P> |
+ Microsoft introduced a shortcut that can be used to reference |
+ elements which include an <ICODE>id</ICODE> attribute where the |
+ <ICODE>id</ICODE> becomes a globally-accessible property. Some browsers reproduce |
+ this behavior. Some, most notably Gecko-based browsers (Netscape and Mozilla), |
+ do so only in "quirks" mode. The best approach is the <ICODE>document.getElementById</ICODE> |
+ method, which is part of the W3C DOM standard and implemented |
+ in modern browsers (including IE from version 5.0). So an |
+ element with <ICODE>id="foo"</ICODE> can be referenced |
+ with:- |
+ </P> |
+ <CODE> |
+var el = document.getElementById("foo"); |
+ </CODE> |
+ <P> |
+ Note: make sure not to use the same <ICODE>id</ICODE> twice in the same document |
+ and do not give an element a <ICODE>name</ICODE> that matches an <ICODE>id</ICODE> |
+ of another in the same document or it will trigger bugs in MSIE <= 7 with |
+ <ICODE>document.getElementsByName</ICODE> and <ICODE>document.getElementById</ICODE>. |
+ </P> |
+ <MOREINFO> |
+ <URL>https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM#Accessing_Elements_with_the_W3C_DOM</URL> |
+ <URL>faq_notes/faq_notes.html#FAQN4_41</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I modify the content of the current page?" |
+ ID="updateContent" NUMID="4_15"> |
+ <P> |
+ Using the non-standard but widely implemented |
+ <ICODE>innerHTML</ICODE> property: |
+ <ICODE><div id="anID">Some Content</div></ICODE> with script: |
+ </P> |
+ <CODE> |
+ document.getElementById("anID").innerHTML = |
+ "Some <em>new</em> Content"; |
+ </CODE> |
+ <P> |
+ Where <ICODE>"anID"</ICODE> is the (unique on the HTML page) |
+ <ICODE>id</ICODE> attribute value of the element to modify. |
+ </P> |
+ <P> |
+All versions of Internet Explorer exhibit problems with innerHTML, including: |
+ </P> |
+ <LIST TYPE="UL"> |
+ <LI>Fails with FRAMESET, HEAD, HTML, STYLE, SELECT, |
+ OBJECT, and all TABLE-related elements.</LI> |
+ <LI>Replaces consecutive whitespace characters with a single space.</LI> |
+ <LI>Changes attribute values and order of appearance.</LI> |
+ <LI>Removes quotations around attribute values.</LI> |
+ </LIST> |
+ <P> |
+ If the new content is only text and does not need to replace existing HTML, |
+ it is more efficient to modify the <ICODE>data</ICODE> property of a text node. |
+ </P> |
+ <CODE> |
+ document.getElementById("anID").firstChild.data = "Some new Text"; |
+ </CODE> |
+ <P> |
+ Compatibility Note: Implementations have been known to split long text |
+ content among several adjacent text nodes, so replacing the data of the |
+ first text node may not replace all the element's text. The <ICODE>normalize</ICODE> |
+ method, where supported, will combine adjacent text nodes. |
+ </P> |
+ <P> |
+ Note: Make sure the element exists in the document (has been parsed) before trying to |
+ reference it. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-FF21A306</URL> |
+ <URL>http://msdn.microsoft.com/en-us/library/cc304097%28VS.85%29.aspx</URL> |
+ <URL>http://msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx</URL> |
+ <URL>http://developer.mozilla.org/en/Whitespace_in_the_DOM</URL> |
+ <URL>http://developer.mozilla.org/en/docs/DOM:element.innerHTML</URL> |
+ <URL>http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm</URL> (draft) |
+ </MOREINFO> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Why does my code fail to access an element?" ID="accessElementBeforeDefined"> |
+ <P> |
+ An element can only be accessed after it exists in the document. |
+ </P> |
+ <P> |
+ Either: |
+ A) include your script after the HTML element it refers to, or |
+ B) use the <ICODE>"load"</ICODE> event to trigger your script. |
+ </P> |
+ <P> |
+ Example A: |
+ </P> |
+ <CODE> |
+<div id="snurgle">here</div> |
+<script type="text/javascript"> |
+// Don't forget var. |
+var snurgleEl = document.getElementById("snurgle"); |
+window.alert(snurgleEl.parentNode); |
+</script> |
+ </CODE> |
+ <P> |
+ Example B: |
+ </P> |
+ <CODE> |
+// In the HEAD. |
+<script type="text/javascript"> |
+window.onload = function(){ |
+ var snurgleEl = document.getElementById("snurgle"); |
+}; |
+</script> |
+ </CODE> |
+ |
+ <LIST TYPE="UL" TITLE="Other problems can include:"> |
+ <LI>invalid HTML</LI> |
+ <LI>two elements with the same <ICODE>name</ICODE> or <ICODE>id</ICODE></LI> |
+ <LI>use of an unsafe name: http://jibbering.com/names/</LI>. |
+ </LIST> |
+ </CONTENT> |
+ <CONTENT TITLE="How can I see in javascript if a web browser accepts cookies?" |
+ ID="testCookie" NUMID="4_4"> |
+ <P> |
+ Write a cookie and read it back and check if it's the same. |
+ </P> |
+ <MOREINFO> |
+ Additional Notes: |
+ <URL>http://www.ietf.org/rfc/rfc2965.txt</URL> |
+ <URL>http://www.galasoft-lb.ch/myjavascript/consulting/2001012701/</URL> |
+ <URL>http://www.cookiecentral.com/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Windows and Frames" ID="windows"> |
+ <P> |
+The <ICODE>window</ICODE> object (also referred to by <ICODE>self</ICODE>) is "DOM Level 0". |
+No formal standard for it exists. |
+</P> |
+ <CONTENT TITLE="How can I disable the back button in a web browser?" ID="disableBackButton" NUMID="4_2"> |
+ <P> |
+You can't. The browser's history cannot be modified. However, you |
+can use <ICODE>self.location.replace(url);</ICODE> in some browsers to replace |
+the current page in the history. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://msdn.microsoft.com/en-us/library/ms536712%28VS.85%29.aspx</URL> |
+ <URL>http://docs.sun.com/source/816-6408-10/location.htm#1194240</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I access a frame's content?" |
+ ID="frameRef" NUMID="4_8"> |
+ <P> |
+To reference another frame on the <EM>same domain</EM>: |
+</P> |
+<P> |
+The <DFN>content window</DFN> of a <ICODE>FRAME</ICODE> or <ICODE>IFRAME</ICODE> can be |
+accessed by the <ICODE>frames</ICODE> collection. |
+</P> |
+<P> |
+Example: |
+</P> |
+<CODE> |
+var fwin; |
+fwin = self.frames[0]; // or: |
+fwin = self.frames["iframeName"]; |
+</CODE> |
+<P>or, from the <ICODE>IFRAME</ICODE> or <ICODE>FRAME</ICODE> element:</P> |
+<CODE> |
+var iframeEl = document.getElementById("myFrame"); |
+var fwin = iframeEl.contentWindow; // Nonstandard, but widely supported. |
+var fdoc = iframeEl.contentDocument; // DOM2 HTML Standard. |
+</CODE> |
+<P> |
+A global identifier <ICODE>moomin</ICODE> in the the iframe's <DFN>content window</DFN> |
+is accessed as <ICODE>fwin.moomin</ICODE>. |
+ </P> |
+ <P> |
+To communicate between frames on <EM>different</EM> domains: |
+</P> |
+<P> |
+Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use |
+<ICODE>window.postMessage( message[, port], otherDomain);</ICODE>. |
+</P> |
+<P> |
+Example: |
+<URL>http://jibbering.com/faq/example/postMessage.html</URL> |
+ </P> |
+ <P> |
+Where <ICODE>window.postMessage</ICODE> is not supported, the <ICODE>window.name</ICODE> property |
+can be set on the other window, which can poll for updates to that |
+property using <ICODE>setInterval(checkWinName, 100);</ICODE> where <ICODE>checkWinName</ICODE> |
+is a function that polls to check the value of |
+<ICODE>self.name</ICODE>. |
+</P> |
+<MOREINFO> |
+<URL>http://en.wikipedia.org/wiki/Same_origin_policy</URL> |
+<URL>http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html</URL> |
+<URL>https://developer.mozilla.org/en/DOM/window.postMessage</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx</URL> |
+</MOREINFO> |
+ |
+ </CONTENT> |
+ <CONTENT TITLE="How do I find the size of the window?" ID="getWindowSize" |
+ NUMID="4_9"> |
+ <P> |
+Here is a detailed explanation of a cross-browser strategy to |
+find the dimensions of the viewport, excepting all chrome |
+(excludes scrollbars, etc). |
+ </P> |
+ <P> |
+We can consider various properties: |
+ </P> |
+ <CODE> |
+ window.innerWidth |
+ document.clientWidth |
+ document.documentElement.clientWidth |
+ document.body.clientWidth |
+ </CODE> |
+ <P> |
+Of the browsers that have an <ICODE>innerWidth</ICODE> property, most |
+include scrollbar dimensions. Some versions of KHTML browsers |
+(including Safari 2) do <EM>not</EM> include scrollbar width. |
+ </P> |
+ |
+ <P> |
+The <ICODE>window.inner*</ICODE> properties are unreliable and not |
+useful here. We don't want scrollbar dimensions included. |
+ </P> |
+<CODE> document.clientWidth</CODE> |
+ <P> |
+Certain versions of KHTML, including Safari 2, have |
+<ICODE>document.clientHeight</ICODE> and <ICODE>document.clientWidth</ICODE> |
+properties. Where supported, these rare properties accurately |
+return the height and width of the viewport, without including |
+scrollbar dimensions. |
+ </P> |
+ <CODE> |
+ document.documentElement.clientWidth |
+ document.body.clientWidth |
+</CODE> |
+<P> |
+MSHTML (Trident), Firefox (Gecko), Opera (Presto), and Safari |
+(Webkit) all support <ICODE>clientHeight</ICODE> on <ICODE>document.body</ICODE> |
+and <ICODE>document.documentElement</ICODE>. The difficulty is figuring out |
+which one is reliable. In other words which object to get the |
+<ICODE>clientHeight</ICODE> property from:<ICODE>documentElement</ICODE> or <ICODE>body</ICODE>? |
+ </P> |
+ |
+ <P> |
+What the number returned from either of these properties |
+represents depends on the environment. The environment includes |
+the browser, its version, and the rendering mode of the document. |
+In quirks mode, we'll mostly want to use <ICODE>body.clientHeight</ICODE> |
+(except for in Safari 2). |
+ </P> |
+ <CODE>document.body.clientHeight</CODE> |
+<P> |
+Some environments will return the viewport height. Others will |
+return <ICODE>0</ICODE>. Yet others will return the <ICODE>clientHeight</ICODE> of |
+the <ICODE>BODY</ICODE> element.</P> |
+ |
+ <CODE> document.documentElement.clientHeight</CODE> |
+<P>This is the more "standard" property for getting the height of |
+the viewport. It usually "works" in modern browsers in |
+<DFN>standards mode</DFN>. Notable exceptions include Safari 2 and |
+Opera <= 9.25, both of which return the <ICODE>clientHeight</ICODE> |
+of the <ICODE>html</ICODE> <EM>element</EM>. (Oddly, Opera <= 9.25 |
+in standards mode returns the width of the viewport for |
+<ICODE>documentElement.clientWidth</ICODE>). |
+ </P> |
+ <P> |
+With the exception of Safari 2, <ICODE>body.clientHeight</ICODE> is reliable |
+where <ICODE>documentElement.clientHeight</ICODE> is found to be unreliable. |
+For example, in Safari 3+, Opera, and Mozilla, all in quirks mode, |
+<ICODE>document.documentElement.clientHeight</ICODE> returns the <ICODE>clientHeight</ICODE> |
+of the <ICODE>html</ICODE> element (this may seem unsurprising but |
+it is not what we want). |
+ </P> |
+ <P> |
+Conversely, <ICODE>document.body.clientHeight</ICODE> will return |
+the height of the viewport in most cases where |
+<ICODE>document.documentElement.clientHeight</ICODE> does not. An exception |
+to that is Safari 2, where <ICODE>documentElement.clientHeight</ICODE> |
+and <ICODE>body.clientHeight</ICODE> both return the height of their |
+corresponding element (not what we want). |
+ </P> |
+ <P> |
+By using a combination of <DFN>Feature Testing</DFN> and <DFN>Capability Testing</DFN>, |
+the dimensions of the viewport can be strategically retrieved |
+from the property that works in the environment the script is |
+running in. The trick is determining which property will give us |
+the value we want. |
+ </P> |
+ <P> |
+Since <ICODE>document.clientHeight</ICODE> is reliable where |
+(rarely) supported, and since browsers that support this property |
+don't return the viewport dimensions from |
+<ICODE>document.body.clientHeight</ICODE> or |
+<ICODE>document.documentElement.clientHeight</ICODE>, this should be the |
+very first condition:</P> |
+ |
+ <CODE> |
+ // Safari 2 uses document.clientWidth (default). |
+ if(typeof document.clientWidth == "number") { |
+ // use document.clientWidth. |
+ } |
+</CODE> |
+ |
+<P>The next strategy is to determine if |
+<ICODE>document.documentElement.clientHeight</ICODE> property is unreliable. |
+It is deemed "unreliable" when it is either <ICODE>0</ICODE> or taller |
+than the viewport. |
+ </P> |
+ <P> |
+ Determining if <ICODE>documentElement.clientHeight</ICODE> is <ICODE>0</ICODE> is easy. |
+ The result is stored in a variable <ICODE>IS_BODY_ACTING_ROOT</ICODE>. |
+ </P> |
+ <CODE> |
+ var docEl = document.documentElement, |
+ IS_BODY_ACTING_ROOT = docEl && docEl.clientHeight === 0; |
+ docEl = null; |
+</CODE> |
+ |
+<P>To determine if <ICODE>documentElement.clientHeight</ICODE> returns |
+a value taller than the viewport, we need a <DFN>Capability Test.</DFN> |
+ </P> |
+ |
+ <P> |
+If we can force <ICODE>documentElement</ICODE> to be very tall |
+(taller than a normal viewport) we can then check to see if |
+<ICODE>documentElement.clientHeight</ICODE> returns that "very tall" number. |
+If it does, then it is unreliable. |
+ </P> |
+ |
+ <P> |
+We can force <ICODE>documentElement</ICODE> to be taller than the viewport |
+(or any "normal" viewport) by adding a <ICODE>div</ICODE> to the <ICODE>body</ICODE>, |
+give that <ICODE>div</ICODE> a height larger than any normal monitor, |
+and then check to see if <ICODE>documentElement.clientHeight</ICODE> is |
+that high (or "almost" that high, to account for <ICODE>documentElement</ICODE> |
+having a border).</P> |
+ |
+ <CODE> |
+ // Used to feature test Opera returning wrong values |
+ // for documentElement.clientHeight. |
+ // The results of this function should be cached, |
+ // so it does not need to be called more than once. |
+ function isDocumentElementHeightOff(){ |
+ var d = document, |
+ div = d.createElement('div'); |
+ div.style.height = "2500px"; |
+ d.body.insertBefore(div, d.body.firstChild); |
+ var r = d.documentElement.clientHeight > 2400; |
+ d.body.removeChild(div); |
+ return r; |
+ } |
+</CODE> |
+ |
+<P>We can use this function to see if we should use |
+<ICODE>body.clientHeight</ICODE>, instead. (but only after checking if |
+<ICODE>document.clientHeight</ICODE> is supported).</P> |
+ |
+ <CODE> |
+ // Safari 2 uses document.clientWidth (default). |
+ if(typeof document.clientWidth == "number") { |
+ // use document.clientHeight/Width. |
+ } |
+ else if(IS_BODY_ACTING_ROOT || isDocumentElementHeightOff()) { |
+ // use document.body.clientHeight/Width. |
+ } else { |
+ // use document.documentElement.clientHeight/Width. |
+ } |
+</CODE> |
+<P> |
+The preceding strategy was developed by Garrett Smith with input |
+from John David Dalton. A complete and tested example can be found |
+in APE Library under <ICODE>APE.dom.getViewportDimensions</ICODE>. |
+Source code: |
+<URL>http://dhtmlkitchen.com/ape/build/dom/viewport-f.js</URL>. |
+APE is publicly released under Academic Free License. |
+APE home: <URL>http://dhtmlkitchen.com/ape/</URL>. |
+ </P> |
+ |
+ <P> |
+ Note: The dimensions cannot be determined accurately until after |
+ the document has finished loading. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://msdn.microsoft.com/en-us/library/ms533566%28VS.85%29.aspx</URL> |
+ <URL>http://developer.mozilla.org/en/DOM/window.innerWidth</URL> |
+ <URL>http://dev.opera.com/articles/view/using-capability-detection/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="How do I check to see if a child window is open, before opening another?" |
+ ID="isWindowOpen" NUMID="4_10"> |
+ <CODE> |
+ var myWin; |
+ function openWin(aURL) { |
+ if (!myWin || myWin.closed ) { |
+ myWin = window.open(aURL,'myWin'); |
+ } else { |
+ myWin.location.href = aURL; |
+ myWin.focus(); |
+ } |
+ }</CODE> |
+<P> |
+Popup windows cause usability problems and are generally best avoided. |
+</P> |
+<MOREINFO> |
+<URL>https://developer.mozilla.org/en/DOM:window.open</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/ms533574%28VS.85%29.aspx</URL> |
+<URL>http://docs.sun.com/source/816-6408-10/window.htm#1201877</URL> |
+<URL>http://www.useit.com/alertbox/990530.html</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="Why does framename.print() not print the correct frame in IE?" |
+ ID="printFrame" NUMID="4_11"> |
+ <P> |
+IE prints the frame that has focus when you call the print |
+method <ICODE>frameref.focus();frameref.print();</ICODE> |
+</P> |
+<MOREINFO> |
+<URL>http://msdn.microsoft.com/en-us/library/ms976105.aspx</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="How do I close a window and why does it not work on the first one?" |
+ ID="windowClose" NUMID="4_14"> |
+ <P> |
+If a window was opened by javascript, then it can be closed |
+without confirmation by using <ICODE>windowRef.close()</ICODE>. |
+</P> |
+<P> |
+Before calling <ICODE>windowRef.close()</ICODE> (or other <ICODE>window</ICODE> methods), make |
+sure the window reference is not null and its <ICODE>closed</ICODE> property is <ICODE>false</ICODE>. |
+</P> |
+<P> |
+Popup windows cause usability problems and are generally best avoided. |
+</P> |
+<MOREINFO> |
+<URL>http://www.useit.com/alertbox/990530.html</URL> |
+<URL>#isWindowOpen</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx</URL> |
+<URL>https://developer.mozilla.org/en/DOM/window.close#Description</URL> |
+<URL>http://docs.sun.com/source/816-6408-10/window.htm#1201822</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="Why do I get permission denied when accessing a frame/window?" |
+ ID="permissionDenied" NUMID="4_19"> |
+ <P> |
+In the normal browser security model, a script may only access the |
+properties of documents served from the same domain or IP address, |
+protocol, and port. |
+ </P> |
+<P> |
+Any attempt to access a property in such cases will result in a "Permission |
+Denied" error. Signed scripts or trusted ActiveX objects can |
+overcome this in limited situations. |
+</P> |
+<MOREINFO> |
+<URL>http://msdn.microsoft.com/en-us/library/ms533028%28VS.85%29.aspx</URL> |
+<URL>https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I make a 10 second delay?" ID="setTimeout" NUMID="4_20"> |
+ <P> |
+There is no built-in way to pause execution in javascript such |
+as a sleep function, but hosts usually provide a method of some |
+form. Web browsers are designed for event driven programming and |
+only provide the <ICODE>setTimeout</ICODE> and <ICODE>setInterval</ICODE> functions |
+to facilitate timed delays. The delay before calling <ICODE>getSnork</ICODE> may |
+exceed the second parameter to <ICODE>setTimeout</ICODE> and <ICODE>setInterval</ICODE> |
+due to implementation differences among browsers. |
+ </P> |
+ <P> |
+ To call the function <ICODE>getSnork</ICODE>, approximately 10 seconds |
+ after the function <ICODE>getMoomin()</ICODE> completes, you would do this: |
+ </P> |
+ <CODE> |
+ getMoomin(); |
+ setTimeout(getSnork, 10000); |
+</CODE> |
+<P>Script execution is not stopped, and adding <ICODE>getSnufkin()</ICODE> after the |
+<ICODE>setTimeout</ICODE> line would immediately execute the function <ICODE>getSnufkin</ICODE> |
+before <ICODE>getSnork</ICODE>. |
+ </P> |
+ <P> |
+Achieving delays through running a loop of some sort for a pre-defined |
+period is a bad strategy, as that will inhibit whatever was supposed to |
+be happening during the delay, including blocking user interation. |
+ </P> |
+ <P> |
+Other (less event driven) hosts have different wait functions, |
+such as <ICODE>WScript.Sleep()</ICODE> in the Windows Script Host. |
+ </P> |
+<MOREINFO> |
+<URL>http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx</URL> |
+<URL>http://docs.sun.com/source/816-6408-10/window.htm#1203758</URL> |
+<URL>http://en.wikipedia.org/wiki/Event-driven_programming</URL> |
+<URL>faq_notes/misc.html#mtSetTI</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="How do I change print settings for window.print()?" |
+ ID="printSettings" NUMID="4_23"> |
+ <P> |
+In a normal security environment, you can't change anything. |
+</P> |
+<P> |
+Print Stylesheet rules provide options. |
+</P> |
+<P>For IE, <ICODE>ActiveX</ICODE> or Plugin ScriptX and |
+Neptune from Meadroid to give you more control for Windows |
+versions of Internet Explorer, Netscape, and Opera. |
+ </P> |
+<MOREINFO> |
+<URL>http://www.meadroid.com/scriptx/</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/ms976105.aspx</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I change the confirm box to say yes/no or default to cancel?" |
+ ID="changeBrowserDialog" NUMID="4_28"> |
+ <P> |
+The buttons on a confirm box cannot be changed, nor can a default |
+button be specified. |
+ </P> |
+<P> |
+Change the question to a statement so that "OK" is suitable as the |
+default response. |
+</P> |
+<P> |
+ Example: |
+ "Would you like us to charge your credit card?" (wrong) |
+ "We will now charge your credit card." (right). |
+</P> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I prompt a "Save As" dialog for an accepted mime type?" |
+ ID="fileDownload" NUMID="4_33"> |
+ <P> |
+It is not possible with client-side javascript. |
+ </P> |
+ <P> |
+Some browsers accept the Content-Disposition header, but this |
+must be added by the server. Taking the form:- |
+<ICODE>Content-Disposition: attachment; filename=filename.ext</ICODE> |
+ </P> |
+<MOREINFO> |
+<URL>http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html</URL> |
+<URL>http://support.microsoft.com/kb/q260519/</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <!-- Can we remove this entry? |
+ http://groups.google.com/group/comp.lang.javascript/msg/c70b57d86300fa91 |
+ |
+ CONTENT TITLE="I have window.status="Moomin"; why doesn't the statusbar change?" |
+ ID="returnValue" NUMID="4_35"> |
+ <P> |
+When changing the status in an event (e.g. <ICODE>onmouseover</ICODE>) you |
+should return true from the event. Also a number of browsers |
+require a short delay before setting the status to overcome their |
+default behaviour with the statusbar. |
+<ICODE>onevent="setTimeout('window.status=\'Moomin\'',15);"</ICODE> |
+ </P> |
+ <P> |
+Many browsers are configured, by default, to disallow scripts from setting |
+the status bar text. Some browsers don't have such a bar, or don't have it by default. |
+ </P> |
+ </CONTENT--> |
+ |
+ <CONTENT TITLE="How do I modify the current browser window?" ID="modifyChrome" NUMID="4_36"> |
+ <P> |
+In a default security environment you are very limited in how much |
+you can modify the current browser window. You can use |
+<ICODE>window.resizeTo</ICODE> or <ICODE>window.moveTo</ICODE> to resize or move a |
+window respectively, but that is it. Normally you can only |
+suggest chrome changes in a <ICODE>window.open</ICODE>. |
+ </P> |
+<MOREINFO> |
+<URL>http://msdn.microsoft.com/en-us/library/ms536651%28VS.85%29.aspx</URL> |
+<URL>https://developer.mozilla.org/en/DOM:window.open</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I POST a form to a new window?" ID="target" NUMID="4_37"> |
+ <P> |
+Use the target attribute on the form, opening a window with |
+that name and your feature string in the onsubmit handler of the |
+FORM. |
+ </P> |
+ <CODE> |
+ <form action="" method="post" |
+ target="wndname" onsubmit="window.open('',this.target);return true;"></CODE> |
+ <MOREINFO> |
+<URL>http://www.htmlhelp.com/reference/html40/forms/form.html</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I open a new window with javascript?" ID="openWindow" NUMID="4_42"> |
+ <P> |
+New windows can be opened on browsers that support the |
+<ICODE>window.open</ICODE> function and are not subject to the action of any |
+pop-up blocking mechanism with code such as:- |
+ </P> |
+ <CODE> |
+ var wRef; |
+ if(window.open){ |
+ wRef = window.open("http://example.com/page.html","windowName"); |
+ }</CODE> |
+<MOREINFO> |
+<URL>https://developer.mozilla.org/en/DOM:window.open</URL> |
+<URL>http://www.infimum.dk/HTML/JSwindows.html</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ <CONTENT TITLE="Ajax and Server Communication" ID="ajaxRef"> |
+ <CONTENT TITLE="What is Ajax?" ID="ajax" NUMID="4_44"> |
+ <P> |
+<DFN TITLE="Asynchronous JavaScript and XML">Ajax</DFN> |
+is shorthand for Asynchronous JavaScript and XML. The technology is |
+based on the <ICODE>XMLHttpRequest</ICODE> Object. At its simplest, |
+it is the sending/retrieving of new data from the server without |
+changing or reloading the window location. |
+ </P> |
+<MOREINFO> |
+Mozilla Documentation: |
+<URL>http://developer.mozilla.org/en/docs/XMLHttpRequest</URL> |
+MSDN Documention: |
+<URL>http://msdn.microsoft.com/en-us/library/ms535874%28VS.85%29.aspx</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/ms759148%28VS.85%29.aspx</URL> |
+ |
+<DFN TITLE="Asynchronous JavaScript and XML">Ajax</DFN> |
+Libraries and Tutorial Sites: |
+<URL>http://jibbering.com/2002/4/httprequest.html</URL> |
+<URL>http://www.ajaxtoolbox.com/</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I download a page to a variable?" ID="downloadPage" NUMID="4_38"> |
+ <P> |
+Although <ICODE>XMLHttpRequest</ICODE> can be used to download |
+entire pages, it is often used for downloading small pieces |
+of data that can be used to update the current page. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://jibbering.com/2002/4/httprequest.html</URL> |
+ <URL>http://www.ajaxtoolbox.com/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I get a jsp/php variable into client-side javascript?" |
+ ID="getServerVariable" NUMID="4_18"> |
+ <P> |
+Use a server-side language to generate the javascript. |
+</P> |
+<P> |
+Certain characters of ECMAScript strings must be escaped by backslash. |
+These include quote marks, backslash, and line terminators. |
+</P> |
+<P>JSP Example, using Apache Commons: <ICODE>org.apache.commons.lang.StringEscapeUtils</ICODE>: |
+</P> |
+ <CODE> |
+var jsVar = "<%= StringEscapeUtils.escapeJavaScript(str) %>"; |
+</CODE> |
+<P>PHP example using <ICODE>addcslashes</ICODE>: </P> |
+<CODE> |
+var jsVar = "<?php echo addcslashes($str,"\\\'\"\n\r"); ?>"; |
+</CODE> |
+ <MOREINFO> |
+ <URL>example/addcslashes.php</URL> |
+ <URL>http://php.net/manual/en/function.addcslashes.php</URL> |
+ <URL>http://commons.apache.org/lang/</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I log-out a user when they leave my site?" |
+ ID="sessionExpired" NUMID="4_29"> |
+ <P> |
+This cannot be done reliably. Here's why: |
+ </P> |
+ <UL> |
+ <LI> |
+The user may disable javascript so the log-out script will |
+never execute. |
+ </LI> |
+ <LI> |
+The user may not be on-line when they close your web page. |
+ </LI> |
+ <LI> |
+Javascript errors elsewhere in the page may prevent the script |
+executing. |
+ </LI> |
+ <LI> |
+The browser may not support the onunload event, or may not fire |
+it under certain circumstances, so the log-out function will |
+not execute. |
+ </LI> |
+ </UL> |
+The URL below has more information. |
+<MOREINFO> |
+<URL>http://groups.google.com/groups?selm=BlmZ7.55691%244x4.7344316%40news2-win.server.ntlworld.com</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I run a server side script?" ID="runServerScript" NUMID="4_34"> |
+ <P> |
+You trigger a server-side script by sending an HTTP request. |
+This can be achieved by setting the <ICODE>src</ICODE> of an <ICODE>img</ICODE>, |
+<ICODE>Image</ICODE>, <ICODE>frame</ICODE>, or <ICODE>iframe</ICODE>, or by using <DFN |
+TITLE="XMLHttpRequest or XMLHTTP">XHR</DFN>, where supported. |
+ </P> |
+ <P> |
+An image will also |
+"swallow" the data sent back by the server, so that they will |
+not be visible anywhere. |
+</P> |
+ <CODE> |
+ var dummyImage = new Image(); |
+ dummyImage.src = "scriptURL.asp?param=" + varName; |
+</CODE> |
+ <P> |
+Mozilla, Opera 7.6+, Safari 1.2+, and Windows IE 7 |
+provide the <ICODE>XMLHttpRequest</ICODE> object |
+(Windows IE versions 5+, provides ActiveX to acheive an analagous |
+effect). <ICODE>XMLHttpRequest</ICODE> can send HTTP requests to |
+the server, and provides access the <ICODE>responseText</ICODE> or <ICODE>responseXML</ICODE> |
+(when the response is XML), and HTTP header information. |
+</P> |
+<MOREINFO> |
+<URL>http://jibbering.com/2002/4/httprequest.html</URL> |
+<URL>http://www.w3.org/TR/XMLHttpRequest/</URL> |
+<URL>http://developer.mozilla.org/en/XMLHttpRequest</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/ms537505(VS.85).aspx</URL> |
+</MOREINFO> |
+ <CONTENT TITLE="Why are my rollovers so slow?" ID="imageCache" NUMID="4_31"> |
+ <P> |
+Images are cached by the browser depending on the headers sent by |
+the server. If the server does not send sufficient information |
+for the browser to decide the image is cacheable, the browser |
+will check if the image has been updated every time you change the |
+src of an image (in some user settings). To overcome this you |
+must send suitable headers. |
+ </P> |
+<MOREINFO> |
+<URL>http://www.mnot.net/cache_docs/</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I force a reload from the server/prevent caching?" |
+ ID="noCache" NUMID="4_17"> |
+ <P> |
+To reload a page, use <ICODE>location.reload()</ICODE>. However, this depends |
+upon the cache headers that your server sends. To change this, |
+you need to alter the server configuration. A quick fix on the |
+client is to change the page URI so that it contains a unique |
+element, such as the current time. For example: |
+<ICODE>location.replace(location.href+'?d='+new Date().valueOf())</ICODE> |
+If the <ICODE>location.href</ICODE> already contains a query String, use: |
+<ICODE>location.replace(location.href+'&d='+new Date().valueOf())</ICODE> |
+ </P> |
+ <MOREINFO> |
+ <URL>http://www.mnot.net/cache_docs/</URL> |
+ <URL>http://docs.sun.com/source/816-6408-10/date.htm</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT |
+ TITLE="Why is my Ajax page not updated properly when using an HTTP GET request in Internet Explorer?" |
+ ID="ajaxCache" NUMID="4_45"> |
+ <P> |
+ Browsers cache the results of HTTP requests to reduce network traffic. |
+ To force the browser to request the document from the server, either |
+ set the <ICODE>EXPIRES</ICODE> and/or <ICODE>CACHE-CONTROL</ICODE> response header(s) |
+ with a past date or use a unique query string. |
+</P> |
+ <CODE> |
+ req.open("GET", "/example.jsp?date=" + (+new Date), true); |
+</CODE> |
+ |
+Always use the appropriate HTTP method. Do not use <ICODE>POST</ICODE> |
+to prevent caching. See <URL LINKTEXT="RFC 2616" |
+>http://www.faqs.org/rfcs/rfc2616.html</URL>. |
+ |
+<MOREINFO> |
+<URL>http://www.mnot.net/cache_docs/#EXPIRES</URL> |
+<URL>http://www.mnot.net/javascript/xmlhttprequest/cache.html </URL> |
+</MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Debugging" ID="debugging"> |
+ <CONTENT TITLE="How do I get my browser to report javascript errors?" |
+ ID="javascriptErrors" NUMID="4_43"> |
+ <P> |
+There are debugging tools for many browsers. Learn to use them all. |
+ </P> |
+ <LIST TYPE="DL"> |
+ <DT>Windows</DT> |
+ <DD> |
+<URL LINKTEXT="Fiddler">http://www.fiddlertool.com/fiddler/</URL>. |
+Fiddler is an HTTP Debugging proxy (it won't find script |
+errors). Fiddler logs HTTP activity, like Firebug's Net |
+tab, but can be attached to any browser running on Windows. |
+ </DD> |
+ <DT>Windows IE</DT> |
+ <DD>Microsoft Script Editor. Included with Visual Studio or Microsoft |
+Word 2003 (discontinued in Office 2007). |
+To enable, |
+<ICODE>Tools</ICODE>, <ICODE>Internet Options</ICODE>, <ICODE>Advanced</ICODE>, and uncheck |
+<ICODE>Disable Script Debugging</ICODE>. After enabling Script Debugging, |
+a <ICODE>Script Debugger</ICODE> option will appear in the <ICODE>View</ICODE> menu.</DD> |
+ |
+<DD><URL LINKTEXT="IETester">http://www.my-debugbar.com/wiki/IETester/HomePage</URL> for testing IE 5.5- IE8.</DD> |
+<DD><URL LINKTEXT="CompanionJS">http://www.my-debugbar.com/wiki/CompanionJS/HomePage</URL> <ICODE>console</ICODE> for IE.</DD> |
+ <DD> |
+<EM>Note:</EM> For debugging scripts in IE, the Microsoft Script <EM>Editor</EM> |
+is recommended. However, if not available, the <URL LINKTEXT="Microsoft Script Debugger" |
+>http://www.microsoft.com/downloads/details.aspx?FamilyId=2F465BE0-94FD-4569-B3C4-DFFDF19CCD99&displaylang=en</URL> may be somewhat helpful. |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Internet Explorer Developer Toolbar" |
+ >http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en</URL> |
+ </DD> |
+ <DD> |
+To report errors: Wait until a little yellow |
+triangle appears at the left end of the status bar, double click |
+on it and, when the error dialog box appears, check the "Always |
+show errors" checkbox it contains. |
+ |
+Or, <ICODE>Internet Options</ICODE>, <ICODE>Advanced</ICODE>, deselect <ICODE>"Disable Script Debugging"</ICODE>, |
+select <ICODE>"Display a notification ..."</ICODE>. |
+ </DD> |
+ <DT>Firefox</DT> |
+ <DD> |
+ <ICODE>Tools > Error console</ICODE> (<ICODE>Ctrl</ICODE> + <ICODE>Shift</ICODE> + <ICODE>j</ICODE>). |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Firebug">http://getfirebug.com/</URL> |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="YSlow">https://addons.mozilla.org/en-US/firefox/addon/5369</URL>. |
+YSlow analyzes web pages and tells you why they're slow |
+based on Yahoo's rules for high performance web sites. |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Lori">https://addons.mozilla.org/en-US/firefox/addon/1743</URL> |
+<DFN>Lori</DFN> or Life-of-request info, is useful for troubleshooting |
+server response and page load time. |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Web Developer Toolbar">https://addons.mozilla.org/en-US/firefox/addon/60</URL>. |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Cookie Watcher">https://addons.mozilla.org/en-US/firefox/addon/1201</URL>. |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="XPather">https://addons.mozilla.org/en-US/firefox/addon/1192</URL>. |
+XPath generator, editor and inspector. |
+ </DD> |
+ <DT>Opera</DT> |
+ <DD> |
+Tools > Advanced > Error console |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Introduction to Opera Dragonfly" |
+ >http://dev.opera.com/articles/view/introduction-to-opera-dragonfly/</URL> |
+ </DD> |
+ <DT>Safari</DT> |
+ <DD> |
+To display the <ICODE>Develop</ICODE> menu in Safari 3.1 or higher, select |
+the checkbox labeled "Show Develop menu in menu bar" in |
+Safari's <ICODE>Advanced</ICODE> Preferences panel. |
+ </DD> |
+ <DD> |
+<URL LINKTEXT="Safari Web Inspector">http://trac.webkit.org/wiki/Web%20Inspector </URL> |
+ </DD> |
+ <DT>Chrome</DT> |
+ <DD> |
+JavaScript Console: click the <ICODE>Page</ICODE> menu icon and select |
+<ICODE>Developer > JavaScript Console</ICODE>. From here, you'll be |
+able to view errors in the JavaScript execution, and enter |
+additional javascript commands to execute. |
+ </DD> |
+ <DD> |
+JavaScript Debugger: available as <ICODE>Page</ICODE> menu icon > <ICODE>Developer</ICODE> |
+> Debug JavaScript, the debugger provides a command prompt from which you |
+can set breakpoints, backtrace, and more. Type <ICODE>help</ICODE> at the debugger |
+command line to get started. |
+ </DD> |
+ <DD> |
+ <UL> |
+ <LI><URL LINKTEXT="Google Chrome Script Debugging" |
+ >http://www.google.com/chrome/intl/en/webmasters-faq.html#jsexec</URL></LI> |
+ <LI><URL LINKTEXT="Developer Tools for Google Chrome" |
+ >http://blog.chromium.org/2009/06/developer-tools-for-google-chrome.html</URL></LI> |
+ <LI><URL LINKTEXT="Tools for Eclipse Users">http://blog.chromium.org/2009/08/google-chrome-developer-tools-for.html</URL></LI> |
+ </UL> |
+ </DD> |
+ <DT>Mac IE</DT> |
+ <DD> |
+Use the Preferences dialog. |
+ </DD> |
+ </LIST> |
+ </CONTENT> |
+ </CONTENT> |
+ <CONTENT TITLE="Things not to attempt in a browser" ID="doNotTry"> |
+ <CONTENT TITLE="How do I detect Opera/Safari/IE?" ID="detectBrowser" NUMID="4_26"> |
+ <P> |
+The short answer: <EM>Don't do that</EM>. |
+ </P> |
+ <P> |
+The <ICODE>navigator</ICODE> <DFN>host object</DFN> contains properties which |
+may identify the browser and version. These properties are historically |
+inaccurate. Some browsers allow the user to set <ICODE>navigator.userAgent</ICODE> to any value. For |
+example, Firefox, (type <ICODE>about:config</ICODE> and search <ICODE>useragent</ICODE> |
+or Safari, <ICODE>Develop > User Agent > Other...</ICODE>, IE, via Registry. |
+ </P> |
+ <P> |
+Other browsers, such as Opera, provide a list of user agents |
+for the user to select from. There are also at least 25 other |
+javascript capable browsers, with multiple versions, each |
+with their own string. |
+ </P> |
+ <P> |
+Browser detection is unreliable, at best. It usually causes |
+forward-compatibility and maintenance problems. It is unrelated to the |
+problem or incompatiblity it is trying to solve and obscures the |
+problems it is used for, where it is used. |
+ </P> |
+ <P> |
+Object detection is checking that the object in question exists. |
+<URL LINKTEXT="Capability detection" |
+>http://dev.opera.com/articles/view/using-capability-detection/</URL |
+ > goes one step further to actually test the object, |
+method, or property, to see if behaves in the desired manner. |
+ </P> |
+ <P> |
+Feature Test Example: |
+ </P> |
+ <CODE> |
+/** |
+ * Returns the element/object the user targeted. |
+ * If neither DOM nor IE event model is supported, returns undefined. |
+ * @throws TypeError if the event is not an object. |
+ */ |
+function getEventTarget(e) { |
+ e = e || window.event; |
+ // First check for the existence of standard "target" property. |
+ return e.target || e.srcElement; |
+}</CODE> |
+<MOREINFO> |
+<URL>notes/detect-browser/</URL> |
+<URL>http://dev.opera.com/articles/view/using-capability-detection/</URL> |
+<URL>http://developer.apple.com/internet/webcontent/objectdetection.html</URL> |
+<URL>http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43</URL> |
+</MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How can I prevent access to a web page by using javascript?" |
+ ID="preventAccess" NUMID="4_5"> |
+ <P> |
+In practice you can't. While you could create a suitable |
+encryption system with a password in the page, the level of |
+support you need to do this means it's always simpler to do it |
+server-side. Anything that "protects" a page |
+other than the current one is definitely flawed. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I protect my javascript code?" ID="hideSource" NUMID="4_1"> |
+ <P> |
+With clientside javascript you can't as your code is distributed |
+in source form and is easily readable. With JScript, there is the |
+Script Encoder (see MSDN), but this is nothing more than obfuscation. |
+Attempting to disable the context menu does nothing to |
+protect your script in a Web browser. |
+ </P> |
+ <MOREINFO> |
+ Your code is likely protected under copyright laws. See: |
+ <URL>http://www.wipo.int/about-ip/en/copyright.html</URL> |
+ <URL>http://webdesign.about.com/od/copyright/Copyright_Issues_on_the_Web_Intellectual_Property.htm</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I suppress a context menu (right-click menu)?" |
+ ID="disableRightClick" NUMID="4_27"> |
+ <P> |
+A context menu, often triggered by right-click, can be requested by the |
+user in a few ways. For example, on windows, shift + F10 and on macs, |
+click-and-hold. Other input devices exist and mouse buttons can be |
+configured, making the term "right click" a misnomer, in context. |
+</P> |
+<P> |
+In browsers that allow it, a script can suppress the context menu by |
+returning false from an object's <ICODE>oncontextmenu</ICODE> event handler. |
+</P> |
+<CODE> |
+document.oncontextmenu = function() { |
+ return false; |
+}; |
+</CODE> |
+<P> |
+Some browsers lack context menus (e.g. iphone). Browsers that have |
+context menus do not always have a scriptable event for them. Some |
+browsers can be configured to disallow scripts from detecting context |
+menu events (IE, Opera); others may fire the event but be configured to |
+disallow scripts from suppressing the context menu (Firefox,Seamonkey). |
+</P> |
+<P> |
+Even when the context menu has been suppressed, it will still be |
+possible to view/save the source code and to save images. |
+</P> |
+<MOREINFO> |
+<URL>http://en.wikipedia.org/wiki/Context_menu</URL> |
+<URL>http://kb.mozillazine.org/Ui.click_hold_context_menus</URL> |
+<URL>http://support.microsoft.com/kb/823057</URL> |
+<URL>http://stackoverflow.com/questions/1870880/opera-custom-context-menu-picking-up-the-right-click/1902730#1902730</URL> |
+<URL>http://support.mozilla.com/en-US/kb/Javascript#Advanced_JavaScript_settings</URL> |
+<URL>http://msdn.microsoft.com/en-us/library/ms536914%28VS.85%29.aspx</URL> |
+</MOREINFO> |
+</CONTENT> |
+ <CONTENT TITLE="How can I access the client-side filesystem?" ID="readFile" NUMID="4_3"> |
+ <P> |
+Security means that by default you can't. In a more restricted |
+environment, there are options. For example, using LiveConnect to |
+connect to Java with Netscape, and using the FileSystemObject in |
+IE. Check <URL LINKTEXT="Google Groups archives">http://groups.google.com/group/comp.lang.javascript/topics</URL> |
+for previous posts on the subject. |
+ </P> |
+ <MOREINFO> |
+ <URL>http://msdn.microsoft.com/en-us/library/z9ty6h50%28VS.85%29.aspx</URL> |
+ <URL>http://www.javaworld.com/javaworld/jw-10-1998/jw-10-apptowin32.html</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ <CONTENT TITLE="I have <a href="javascript:somefunction()"> what ... ?" |
+ ID="javascriptURI" NUMID="4_24"> |
+ <P> |
+Whatever the rest of your question, this is generally a very bad idea. |
+The <ICODE>javascript:</ICODE> pseudo protocol was designed to replace the |
+current document with the value that is returned from the expression. |
+For example: |
+ </P> |
+ <CODE> |
+ <a href="javascript:'<h1>' + document.lastModified + '</h1>'">lastModified</a> |
+</CODE> |
+ <P> |
+will result in replacing the current document with the value |
+returned from <ICODE>document.lastModified</ICODE>, wrapped in an <ICODE><h1></ICODE> |
+tag. |
+ </P> |
+ <P> |
+When the expression used evaluates to an <ICODE>undefined</ICODE> value |
+(as some function calls do), the contents of the current page are not |
+replaced. Regardless, some browsers (notably IE6) interpret this as |
+navigation and will enter into a 'navigation' state where GIF |
+animations and plugins (such as movies) will stop and navigational |
+features such as <ICODE>META</ICODE> refresh, assignment to <ICODE>location.href</ICODE>, and image |
+swaps fail. |
+ </P> |
+ <P> |
+It is also possible for IE to be configured such that it supports |
+javascript but not the <ICODE>javascript:</ICODE> protocol. This results |
+in the user seeing a protocol error for <ICODE>javascript:</ICODE> URIs. |
+ </P> |
+ <P> |
+The <ICODE>javascript:</ICODE> pseudo protocol creates accessibility and |
+usability problems. It provides no fallback for when the script is not |
+supported. |
+ </P> |
+ <P> |
+Instead, use |
+<ICODE><a href="something.html" onclick="somefunction();return false"></ICODE> |
+where <ICODE>something.html</ICODE> is a meaningful alternative. Alternatively, |
+attach the <ICODE>click</ICODE> callback using an event registry. |
+ </P> |
+ <MOREINFO> |
+ <URL>example/jsuri/</URL> |
+ <URL LINKTEXT="Set/Navigate to a Location">http://groups.google.com/group/comp.lang.javascript/msg/f665cfca3b619692</URL> |
+ <URL LINKTEXT="Top Ten Web-Design Mistakes of 2002">http://www.useit.com/alertbox/20021223.html</URL> |
+ </MOREINFO> |
+ </CONTENT> |
+ </CONTENT> |
+ |
+ <CONTENT TITLE="Comments and Suggestions" ID="comments" NUMID="5"> |
+ <P HTMLONLY="true"> |
+ This FAQ uses the CSS stylesheet <URL>faq.css</URL> and is generated |
+ from the XML source <URL>index.xml</URL> using the XSLT stylesheet |
+ <URL>index.xsl</URL><!-- which also checks the links -->. |
+ </P> |
+ <CONTENT TITLE="Why do some posts have <FAQENTRY> in them?" ID="FAQENTRY" NUMID="5_1"> |
+ <P> |
+ If a poster feels that the question they are answering should be |
+ covered in the FAQ, placing <FAQENTRY> in the post lets the FAQ |
+ robot collect the messages for easy review and inclusion. A Draft Proposal |
+ for the FAQ is requested and appreciated. |
+ </P> |
+ <P> |
+The <FAQENTRY> should not be used in posts except in |
+conjunction with a suggestion/proposal for this FAQ. It should |
+also not be literally quoted in replies, instead it should be |
+partly obscured as, e.g. <FAQ**TRY> or similar. |
+ </P> |
+ </CONTENT> |
+ <CONTENT TITLE="How do I make a suggestion?" NUMID="5_2" ID="makeSuggestion"> |
+ <P> |
+To make a suggestion to this FAQ, use either the FAQENTRY method |
+above, or e-mail Thomas 'PointedEars' Lahn <cljs@PointedEars.de> (editor). |
+All comments, suggestions, and especially corrections are welcome. |
+ </P> |
+ </CONTENT> |
+ <!-- FIXME --> |
+ <!-- |
+ <P> |
+ This FAQ is (C) Copyright Contributors on behalf of the |
+ newsgroup comp.lang.javascript. Upon change of the FAQ maintainer, |
+ the copyright will automatically pass over to the new maintainer. |
+ </P> |
+ --> |
+ </CONTENT> |
</CONTENTS> |
-</FAQ> |
\ No newline at end of file |
+</FAQ> |