Compare Revisions
Last modification
- Rev 6 2012-12-16 02:23:22
- Author: PointedEars
- Log message:
cljs: Moved obsolete files to backup/
/trunk/cljs/index.html |
File deleted |
|
Property changes: |
Deleted: svn:mime-type |
## -1 +0,0 ## |
-text/plain |
\ No newline at end of property |
Index: cljs/process.wsf |
=================================================================== |
--- cljs/process.wsf (revision 5) |
+++ cljs/process.wsf (nonexistent) |
@@ -1,387 +0,0 @@ |
-<job id="process"> |
-<!-- |
-This file generates the FAQ index.html |
---> |
-<SCRIPT> |
-/** |
- * Formatting - Still messy. |
- * Needed corrections: |
- * statements terminated with semicolon. |
- * use |var| for variables. |
- * use whitespace. |
- * 2 spaces for indentation (not one). |
- */ |
-var CheckUrls=false, |
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
- |
-// moomin.utilities can be got from http://www.e-media.co.uk/earl/ |
-// var mu=new ActiveXObject("Moomin.Utilities") |
- |
-var xml = new ActiveXObject("Microsoft.XMLDOM"); |
-xml.async = false; |
-xml.validateOnParse = false; |
-xml.resolveExternals = false; |
-xml.load("index.xml"); |
-xml.save("indexold.xml"); |
- |
-var faqNode = xml.selectSingleNode("/FAQ"), |
- Version = faqNode.attributes.getNamedItem("VERSION").nodeValue, |
- maintainer = "Garrett Smith", |
- Updated = faqNode.attributes.getNamedItem("DATE").nodeValue; |
- |
-var str = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" \n' |
- + '"http://www.w3.org/TR/html4/strict.dtd">\n<html lang="en">\n' |
- + '<head>\n' |
- + '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n' |
- + '<meta name="DCTERMS.language" scheme="RFC1766" content="en">\n' |
- + '<meta name="DC.title" content="comp.lang.javascript Frequently Asked Questions">\n' |
- + '<meta name="DCTERMS.subject" ' |
- + 'content="Frequently asked questions in the Usenet newsgroup comp.lang.javascript">\n' |
- + '<meta name="DC.format" content="text/html">\n' |
- + '<meta name="DC.type" content="Text">\n' |
- + '<meta name="DC.creator" content="Jim Ley">\n' |
- + '<meta name="DC.publisher" content="' + maintainer + '">\n' |
- + '<META name="DC.Publisher.Address" ' |
- + 'content="dhtmlkitchen@gmail.com">\n' |
- + '<meta name="DCTERMS.modified" content="' + Updated +'">\n' |
- + '<meta name="DCTERMS.audience" content="Programmers, web developers">\n' |
- + '<meta name="DC.description" content="Javascript Frequently Asked Questions">\n' |
- + '<meta name="DC.identifier" content="http://jibbering.com/faq">\n' |
- + '<meta name="DC.source" ' |
- + 'content="http://www.ecma-international.org/publications/standards/Ecma-262.htm">\n' |
- + '<meta name="DC.source" content="news:comp.lang.javascript">\n' |
- + '<meta name="DC.source" content="https://developer.mozilla.org/en/JavaScript">\n' |
- + '<meta name="DC.source" content="http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx">\n' |
- + '<meta name="DC.source" content="http://msdn.microsoft.com/en-us/library/ms533050%28VS.85%29.aspx">\n' |
- + '<meta name="DC.rights" content="copyright contributors, comp.lang.javascript">\n' |
- + '<link rel="StyleSheet" href="faq.css" type="text/css" media="screen">\n'; |
- |
-TitleStr = xml.selectSingleNode("/FAQ/TITLE").firstChild.nodeValue; |
- |
-str += "<title> "+TitleStr+"</title>\n" |
- + '</head>\n <body>\n' |
- + "<h1> "+TitleStr+"</h1>\n" |
- + "<p>Version "+Version+", Updated "+Updated +", by " + maintainer + "</p>" |
- + '<div id="nav"><a href="notes/">FAQ Notes</a></div>'; |
- |
-var contentstr = ""; |
-Contents = xml.selectSingleNode("/FAQ/CONTENTS").selectNodes("CONTENT"); |
- |
-str += "\n<ul id='faqList'>\n"; |
- |
-for (var i = 0; i < Contents.length; i++) { |
- CNode = Contents[i]; |
- var sectionId = CNode.getAttribute("ID") || "", |
- title = CNode.getAttribute("TITLE"); |
- |
- str += "<li>" + (i+1) + " <a href='#" + sectionId +"'>" + title + "</a>\n"; |
- |
- contentstr += "<div id='" + sectionId +"' class='section'>" |
- + "<h2"+getOldId(CNode)+">" |
- + (i+1) + " " + title |
- + "</h2>\n" |
- + processContentChildren(CNode) |
- + "</div>"; |
- |
- var SubContents = CNode.selectNodes("CONTENT"); |
- processContentChildren(CNode); |
- if(SubContents.length > 0) { |
- str += "\n<ul>\n"; |
- |
- // Build a link to a subsection. |
- // a subsection looks like: |
- // <h3 id=[FAQ5_7 | getWindowSize]><a name=FAQ5_7></a> ... </h3> |
- // This allows for items to be moved around in various |
- // order (index should not matter). |
- |
- for (var j = 0; j < SubContents.length; j++) { |
- var SubCNode = SubContents[j], |
- subSectionId = SubCNode.getAttribute("ID"), |
- title = SubCNode.getAttribute("TITLE"), |
- entryNumber = ""+(i+1)+"."+ (j+1); |
- |
- str += "<li>" + entryNumber +" <a href='#"+ subSectionId +"'>" + title + "</a></li>\n"; |
- |
- contentstr += "<div id='" + subSectionId + "' class='section'>" |
- + "<h3" + getOldId(SubCNode) + ">" |
- + entryNumber + " " + title |
- + '</h3>' |
- + processContentChildren(SubCNode ) |
- + '</div>' |
- + '\n'; |
- } |
- str += "</ul>"; |
- } |
- str += "</li>"; |
-} |
- |
-/** |
- * If the node contains a "NUMID", |
- * the content is wrapped in an anchor, e.g. "<a name='" + NUMID. |
- * Otherwise, returns the content. |
- */ |
-function getOldId(node) { |
- var faqSectionIndexString = node.getAttribute("NUMID") || ""; |
- return (faqSectionIndexString ? |
- " id='FAQ" + faqSectionIndexString +"'" : ""); |
-} |
- |
-str += "</ul>" |
- + contentstr |
- + "<!--<script src='FAQReader.js' type='text/javascript'><\/script>-->" |
- + "</body> \n</html> \n"; |
-str = str.replace(/<p><\/p>/gm,"").replace(/<p> <\/p>/gm,""); |
- |
-// Create the files. |
-var FSO = new ActiveXObject("Scripting.FileSystemObject"); |
-FIL = FSO.CreateTextFile("index"+Version+".html",true); |
-FIL.WriteLine(str); |
-FIL.close(); |
-FIL=FSO.CreateTextFile("index.html",true); |
-FIL.WriteLine(str); |
-FIL.close(); |
-if (CheckUrls) { |
- xml.save("index.xml"); |
- xml.save("index"+Version+".xml"); |
-} |
- |
-function processContentChildren(cNode) { |
- var allNodes = cNode.selectNodes("*"), |
- contentstr = "";; |
- for(var k = 0; k < allNodes.length; k++) { |
- var node = allNodes[k]; |
- if(node.tagName == "P") |
- contentstr += ProcessNode(node); |
- |
- // List nodes, for UL, OL, DL. |
- else if(node.tagName == "LIST") |
- contentstr += processList(allNodes[k]); |
- } |
- return contentstr; |
-} |
- |
-function ProcessNode(nde) { |
- var str = " ", p = "", closeP = "", child; |
- if(nde.tagName == "P") { |
- str = "<p>\n "; |
- p = "<p>"; |
- closeP = "</p>"; |
- } |
- for (var i = 0;i < nde.childNodes.length; i++) { |
- child = nde.childNodes[i]; |
- switch (child.nodeName) { |
- case "#comment" : |
- str += "<!--" + child.data + "-->"; |
- break; |
- case "#text" : |
- // If a text node is empty, do not generate an empty <p> tag. |
- if(child.nodeValue.replace(/\s+/,'') == "") return " "; |
- str += child.nodeValue; |
- break; |
- case "VER" : |
- str += Version; |
- break; |
- case "UPDATED" : |
- str += Updated; |
- break; |
- case "URL" : |
- str += makeLink(child); |
- break; |
- case "EM" : |
- var url= child.firstChild.nodeValue; |
- str+=' <em>'+url+'</em>'; |
- break; |
- case "NEWSGROUP" : |
- var url= child.firstChild.nodeValue; |
- str+=' <a href="news:'+url+'">'+url+'</a>'; |
- break; |
- case "MAILTO" : |
- var url= child.firstChild.nodeValue; |
- str+=' <a href="mailto:'+url+'">'+url+'</a>'; |
- break; |
- case "MOREINFO" : |
- str += closeP + ProcessResource(child) + p; |
- break; |
- case "UL" : |
- str+= closeP + " \n<ul> "+ProcessUL(nde.childNodes[i])+"</ul> \n" + p; |
- break; |
- case "LI" : |
- str+="<li> "+ ProcessNode( child ) + "</li>"; |
- break; |
- case "CODE" : |
- str+= closeP + "\n<pre>"+ child.firstChild.nodeValue +"</pre>\n"+p; |
- break; |
- case "ICODE" : |
- str += "<code>"+ child.firstChild.nodeValue+"</code>"; |
- break; |
- case "DFN" : |
- var title = child.attributes.getNamedItem("TITLE"); |
- title = title && (" title = '" + title.nodeValue +"'") || ""; |
- str +="\n<dfn" + title + ">" |
- + child.firstChild.nodeValue + "</dfn>"; |
- break; |
- default: |
- str += child.nodeValue; |
- break; |
- } |
- } |
- return str+= closeP + " "; |
-} |
- |
-function makeLink(child) { |
- var url = child.firstChild.nodeValue, |
- linkText = child.attributes.getNamedItem("LINKTEXT"), |
- addstr = checkUrl(url, child); |
- linkText = linkText && linkText.nodeValue; |
- return '<a href="'+url+'" '+addstr+'>'+(linkText||url)+'</a>'; |
-} |
- |
-/** Processing for OL, UL, DL. |
- * calls processNode. |
- */ |
-function processList(list) { |
- var str = "", |
- header = "", |
- title = list.getAttribute("TITLE"), |
- id = list.getAttribute("ID"), |
- idStr = (id && " id='" + id + "'") || ""; |
- |
- if(title) { |
- header = "\n<h4" + idStr +">" + title + "</h4>\n"; |
- idStr = ""; // Output id only once. |
- } |
- |
- var type = list.getAttribute("TYPE"); |
- type = (type || "ul").toLowerCase(); |
- |
- str += "\n<" + type + idStr +">"; |
- |
- for (var i = 0; i < list.childNodes.length; i++) { |
- var child = list.childNodes[i], |
- tagName = child.nodeName; |
- |
- // If not a list-type element, |
- // add it to the header (will appear first). |
- if(!/(?:LI)|(?:DT)|(?:DD)/.test(tagName)) { |
- header += ProcessNode(child); |
- } |
- else if(tagName !== "#text") { |
- tagName = tagName.toLowerCase(); |
- str += "\n <" +tagName +">" + ProcessNode(child) + "</" +tagName +">"; |
- } |
- } |
- return header + str + "</" + type + ">"; |
-} |
- |
- function ProcessUL(nde) { |
- var str="" |
- for (var i=0;i<nde.childNodes.length;i++) { |
- |
- var child = nde.childNodes[i]; |
- |
- switch (nde.childNodes[i].nodeName) { |
- case "#text" : |
- str+=nde.childNodes[i].nodeValue; |
- break; |
- case "VER" : |
- str+=Version |
- break; |
- case "URL" : |
- str += makeLink(child); |
- break; |
- case "NEWSGROUP" : |
- var url = child.firstChild.nodeValue |
- str+=' <a href="news:'+url+'">'+url+'</a> \n' |
- break; |
- case "MAILTO" : |
- var url= child.firstChild.nodeValue; |
- str+=' <a href="mailto:'+url+'">'+url+'</a> \n' |
- break; |
- case "UL" : |
- str+="<ul>\n" + ProcessNode(child) + "\n</ul>\n" |
- break; |
- case "LI" : |
- str+="<li> " + ProcessNode(child) + "</li> \n" |
- break; |
- case "CODE" : |
- str+="</p>\n<pre>"+nde.childNodes[i].firstChild.nodeValue.replace('\r',"<BR> ")+"</pre> \n<p> \n" |
- break; |
- case "ICODE" : |
- str+="<code>"+nde.childNodes[i].firstChild.nodeValue+"</code>\n" |
- break; |
- default: |
- document.write(nde.childNodes[i].nodeName+'<br> \n') |
- str+=nde.childNodes[i].nodeValue; |
- break; |
- } |
- } |
- return str += ""; |
- } |
- |
- |
-function ProcessResource(nde) { |
- var str="<ul class='linkList'>", child; |
- for (var i = 0; i < nde.childNodes.length; i++) { |
- child = nde.childNodes[i]; |
- switch (child.nodeName) { |
- case "#text" : |
- if(/[a-zA-Z]/.test(child.nodeValue)) |
- str += '<li>' + child.nodeValue + '</li>\n'; |
- break; |
- case "URL" : |
- str+='<li>' + makeLink(child) + '</li>\n'; |
- break; |
- case "NEWSGROUP" : |
- var url = child.firstChild.nodeValue; |
- str += '<li><a href="news:'+url+'">' + url + '</a></li> \n'; |
- break; |
- |
- } |
- } |
- return str + "</ul>"; |
-} |
- |
- function checkUrl(url,node) { |
- url=url.split('#')[0] |
- if (CheckUrls) { |
- if (url.indexOf('http://')==0) { |
- xmlhttp.Open("get",url,false) |
- try { |
- xmlhttp.Send() |
- } catch (e) { WScript.Echo(url);return ""; } |
- stat=xmlhttp.status |
- node.attributes.getNamedItem("status").nodeValue=stat |
- if (stat==200) { |
- source=xmlhttp.responseText |
- if (url.indexOf('microsoft')!=-1 && source.indexOf('Page Cannot')!=-1) { |
- //Ugly hack 'cos MSDN don't understand HTTP. |
- stat=404 |
- node.attributes.getNamedItem("status").nodeValue=stat |
- return ' class="nolink" ' |
- } |
- contentlength=source.length |
-// oldhash=node.attributes.getNamedItem("hash").nodeValue |
-// hash=mu.MD5(source,"faq") |
-// node.attributes.getNamedItem("hash").nodeValue=hash |
- classstr="" |
-// if (oldhash!=hash) classstr=' class="updated"' |
- lm=xmlhttp.getResponseHeader("Last-Modified") |
- return classstr+' title="'+lm+'" ' |
- } else { |
- xmlhttp.Open("get","http://www.google.com/search?q=cache:"+url,false) |
- xmlhttp.Send() |
- if (xmlhttp.responseText.indexOf('did not match any documents')==-1) { |
- return ' class="nolink"> \n<small> \n<a href="http://www.google.com/search?q=cache:'+url+'>(Googles cached copy)</a> \n<small' |
- } |
- return ' class="nolink" ' |
- } |
- } else { |
- return "" |
- } |
- } else { |
- return "" |
- } |
- |
- } |
-</SCRIPT> |
-</job> |
Index: cljs/backup/index.html |
=================================================================== |
--- cljs/backup/index.html (nonexistent) |
+++ cljs/backup/index.html (revision 6) |
@@ -0,0 +1,2110 @@ |
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
+"http://www.w3.org/TR/html4/strict.dtd"> |
+<html lang="en"> |
+<head> |
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
+<meta name="DCTERMS.language" scheme="RFC1766" content="en"> |
+<meta name="DC.title" content="comp.lang.javascript Frequently Asked Questions"> |
+<meta name="DCTERMS.subject" content="Frequently asked questions in the Usenet newsgroup comp.lang.javascript"> |
+<meta name="DC.format" content="text/html"> |
+<meta name="DC.type" content="Text"> |
+<meta name="DC.creator" content="Jim Ley"> |
+<meta name="DC.publisher" content="Garrett Smith"> |
+<META name="DC.Publisher.Address" content="dhtmlkitchen@gmail.com"> |
+<meta name="DCTERMS.modified" content="2010-10-08"> |
+<meta name="DCTERMS.audience" content="Programmers, web developers"> |
+<meta name="DC.description" content="Javascript Frequently Asked Questions"> |
+<meta name="DC.identifier" content="http://jibbering.com/faq"> |
+<meta name="DC.source" content="http://www.ecma-international.org/publications/standards/Ecma-262.htm"> |
+<meta name="DC.source" content="news:comp.lang.javascript"> |
+<meta name="DC.source" content="https://developer.mozilla.org/en/JavaScript"> |
+<meta name="DC.source" content="http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx"> |
+<meta name="DC.source" content="http://msdn.microsoft.com/en-us/library/ms533050%28VS.85%29.aspx"> |
+<meta name="DC.rights" content="copyright contributors, comp.lang.javascript"> |
+<link rel="StyleSheet" href="faq.css" type="text/css" media="screen"> |
+<title> comp.lang.javascript FAQ</title> |
+</head> |
+ <body> |
+<h1> comp.lang.javascript FAQ</h1> |
+<p>Version 32.2, Updated 2010-10-08, by Garrett Smith</p><div id="nav"><a href="notes/">FAQ Notes</a></div> |
+<ul id='faqList'> |
+<li>1 <a href='#meta'>Meta-FAQ meta-questions</a> |
+ |
+<ul> |
+<li>1.1 <a href='#newsgroups'>Which newsgroups deal with javascript?</a></li> |
+<li>1.2 <a href='#appropriateQuestions'>What questions are on-topic for comp.lang.javascript?</a></li> |
+<li>1.3 <a href='#posting'>What should I do before posting to comp.lang.javascript?</a></li> |
+<li>1.4 <a href='#noAnswer'>Why was my post not answered?</a></li> |
+</ul></li><li>2 <a href='#tips'>Language Overview</a> |
+ |
+<ul> |
+<li>2.1 <a href='#ecma'>What is ECMAScript?</a></li> |
+<li>2.2 <a href='#jScript'>What is JScript?</a></li> |
+<li>2.3 <a href='#dom'>What is the Document Object Model (DOM)?</a></li> |
+<li>2.4 <a href='#localization'>Internationalisation and Localisation in javascript</a></li> |
+<li>2.5 <a href='#futureEcmaScript'>What does the future hold for ECMAScript?</a></li> |
+</ul></li><li>3 <a href='#ecmascriptResources'>Javascript Resources</a> |
+ |
+<ul> |
+<li>3.1 <a href='#books'>What books are recommended for javascript?</a></li> |
+<li>3.2 <a href='#onlineResources'>What online resources are available?</a></li> |
+<li>3.3 <a href='#libraryResources'>Javascript Libraries</a></li> |
+</ul></li><li>4 <a href='#functions'>Functions</a> |
+ |
+<ul> |
+<li>4.1 <a href='#scope'>What is (function(){ /*...*/ })() ?</a></li> |
+<li>4.2 <a href='#functionStatement'>What is a function statement?</a></li> |
+</ul></li><li>5 <a href='#dates'>Dates</a> |
+ |
+<ul> |
+<li>5.1 <a href='#formatDate'>How do I format a Date object with javascript?</a></li> |
+<li>5.2 <a href='#parseDate'>How can I create a Date object from a String?</a></li> |
+</ul></li><li>6 <a href='#numbers'>Numbers</a> |
+ |
+<ul> |
+<li>6.1 <a href='#formatNumber'>How do I format a Number as a String with exactly 2 decimal places?</a></li> |
+<li>6.2 <a href='#binaryNumbers'>Why does simple decimal arithmetic give strange results?</a></li> |
+<li>6.3 <a href='#parseIntBase'>Why does K = parseInt('09') set K to 0?</a></li> |
+<li>6.4 <a href='#typeConvert'>Why does 1+1 equal 11? or How do I convert a string to a number?</a></li> |
+<li>6.5 <a href='#randomNumber'>How do I generate a random integer from 1 to n?</a></li> |
+</ul></li><li>7 <a href='#objects'>Objects</a> |
+ |
+<ul> |
+<li>7.1 <a href='#nativeObject'>What is a native object?</a></li> |
+<li>7.2 <a href='#builtInObject'>What is a built-in object?</a></li> |
+<li>7.3 <a href='#hostObject'>What is a host object?</a></li> |
+<li>7.4 <a href='#eval'>When should I use eval?</a></li> |
+<li>7.5 <a href='#propertyAccessAgain'>How do I access a property of an object using a string?</a></li> |
+</ul></li><li>8 <a href='#strings'>Strings and RegExp</a> |
+ |
+<ul> |
+<li>8.1 <a href='#trimString'>How do I trim whitespace?</a></li> |
+</ul></li><li>9 <a href='#domRef'>DOM and Forms</a> |
+ |
+<ul> |
+<li>9.1 <a href='#formControlAccess'>How do I get the value of a form control?</a></li> |
+<li>9.2 <a href='#propertyAccess'>My element is named myselect[], how do I access it?</a></li> |
+<li>9.3 <a href='#globalPollution'>Why doesn't the global variable "divId" always refer to the element with id="divId"?</a></li> |
+<li>9.4 <a href='#updateContent'>How do I modify the content of the current page?</a></li> |
+<li>9.5 <a href='#accessElementBeforeDefined'>Why does my code fail to access an element?</a></li> |
+<li>9.6 <a href='#testCookie'>How can I see in javascript if a web browser accepts cookies?</a></li> |
+</ul></li><li>10 <a href='#windows'>Windows and Frames</a> |
+ |
+<ul> |
+<li>10.1 <a href='#disableBackButton'>How can I disable the back button in a web browser?</a></li> |
+<li>10.2 <a href='#frameRef'>How do I access a frame's content?</a></li> |
+<li>10.3 <a href='#getWindowSize'>How do I find the size of the window?</a></li> |
+<li>10.4 <a href='#isWindowOpen'>How do I check to see if a child window is open, before opening another?</a></li> |
+<li>10.5 <a href='#printFrame'>Why does framename.print() not print the correct frame in IE?</a></li> |
+<li>10.6 <a href='#windowClose'>How do I close a window and why does it not work on the first one?</a></li> |
+<li>10.7 <a href='#permissionDenied'>Why do I get permission denied when accessing a frame/window?</a></li> |
+<li>10.8 <a href='#setTimeout'>How do I make a 10 second delay?</a></li> |
+<li>10.9 <a href='#printSettings'>How do I change print settings for window.print()?</a></li> |
+<li>10.10 <a href='#changeBrowserDialog'>How do I change the confirm box to say yes/no or default to cancel?</a></li> |
+<li>10.11 <a href='#fileDownload'>How do I prompt a "Save As" dialog for an accepted mime type?</a></li> |
+<li>10.12 <a href='#modifyChrome'>How do I modify the current browser window?</a></li> |
+<li>10.13 <a href='#target'>How do I POST a form to a new window?</a></li> |
+<li>10.14 <a href='#openWindow'>How do I open a new window with javascript?</a></li> |
+</ul></li><li>11 <a href='#ajaxRef'>Ajax and Server Communication</a> |
+ |
+<ul> |
+<li>11.1 <a href='#ajax'>What is Ajax?</a></li> |
+<li>11.2 <a href='#downloadPage'>How do I download a page to a variable?</a></li> |
+<li>11.3 <a href='#getServerVariable'>How do I get a jsp/php variable into client-side javascript?</a></li> |
+<li>11.4 <a href='#sessionExpired'>How do I log-out a user when they leave my site?</a></li> |
+<li>11.5 <a href='#runServerScript'>How do I run a server side script?</a></li> |
+<li>11.6 <a href='#noCache'>How do I force a reload from the server/prevent caching?</a></li> |
+<li>11.7 <a href='#ajaxCache'>Why is my Ajax page not updated properly when using an HTTP GET request in Internet Explorer?</a></li> |
+</ul></li><li>12 <a href='#debugging'>Debugging</a> |
+ |
+<ul> |
+<li>12.1 <a href='#javascriptErrors'>How do I get my browser to report javascript errors?</a></li> |
+</ul></li><li>13 <a href='#doNotTry'>Things not to attempt in a browser</a> |
+ |
+<ul> |
+<li>13.1 <a href='#detectBrowser'>How do I detect Opera/Safari/IE?</a></li> |
+<li>13.2 <a href='#preventAccess'>How can I prevent access to a web page by using javascript?</a></li> |
+<li>13.3 <a href='#hideSource'>How do I protect my javascript code?</a></li> |
+<li>13.4 <a href='#disableRightClick'>How do I suppress a context menu (right-click menu)?</a></li> |
+<li>13.5 <a href='#readFile'>How can I access the client-side filesystem?</a></li> |
+<li>13.6 <a href='#javascriptURI'>I have <a href="javascript:somefunction()"> what ... ?</a></li> |
+</ul></li><li>14 <a href='#comments'>Comments and Suggestions</a> |
+ |
+<ul> |
+<li>14.1 <a href='#FAQENTRY'>Why do some posts have <FAQENTRY> in them?</a></li> |
+<li>14.2 <a href='#makeSuggestion'>How do I make a suggestion?</a></li> |
+</ul></li></ul><div id='meta' class='section'><h2 id='FAQ1'>1 Meta-FAQ meta-questions</h2> |
+<p> |
+ |
+This is the <em>comp.lang.javascript</em> meta-FAQ, 32.2. The latest |
+version is available at <a href="http://jibbering.com/faq/" >http://jibbering.com/faq/</a> 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 |
+<a href="notes/" >FAQ Notes</a>. |
+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 <a href="http://jsdoctoolkit.org/" >JSDoc Toolkit</a> comments. |
+</p> </div><div id='newsgroups' class='section'><h3 id='FAQ2_1'>1.1 Which newsgroups deal with javascript?</h3><p> |
+ |
+The official Big 8 Usenet newsgroup dealing with javascript is |
+ <a href="news:comp.lang.javascript">comp.lang.javascript</a>. |
+Some "language" hierarchies also have *.comp.lang.javascript groups. |
+ </p> <p> |
+ |
+c.l.js is an unmoderated newsgroup. |
+ </p> </div> |
+<div id='appropriateQuestions' class='section'><h3 id='FAQ2_2'>1.2 What questions are on-topic for comp.lang.javascript?</h3><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 that are specific to Microsoft's JScript may also |
+be appropriately asked at: |
+ <a href="news:microsoft.public.scripting.jscript">microsoft.public.scripting.jscript</a></p> <p> |
+ |
+The comp.lang.javascript newsgroup charter is included in |
+<a href="faq_notes/cljs_charter.html" >faq_notes/cljs_charter.html</a>. |
+ </p> </div> |
+<div id='posting' class='section'><h3 id='FAQ2_3'>1.3 What should I do before posting to comp.lang.javascript?</h3><p> |
+ |
+Before posting to c.l.js, you should read this document. |
+You should also check the <a href="#onlineResources" >Resources section</a>. |
+ </p> |
+<h4 id='ask'>How to Ask a Question</h4> |
+ |
+<ul> |
+ <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 |
+ <a href="notes/posting/" >"Posting Questions and Replies to comp.lang.javascript"</a>. |
+ </li></ul> |
+<h4 id='reply'>Replying</h4> |
+ |
+<ul> |
+ <li> |
+Quote only relevant parts of earlier messages, and add your |
+comments below each quoted section |
+(<a href="http://www.ietf.org/rfc/rfc1855.txt" >FYI28/RFC1855</a>). |
+ </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></ul> |
+<h4 id='postCode'>Posting Code</h4> |
+ |
+<ul> |
+ <li> |
+Remove everything that does not contribute to the problem (images, |
+markup, other scripts, etc). |
+ </li> |
+ <li> |
+Validate the HTML and CSS <a href="http://validator.w3.org/" >http://validator.w3.org/</a>, <a href="http://jigsaw.w3.org/css-validator/" >http://jigsaw.w3.org/css-validator/</a>. |
+ </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 <a href="#debugging" >FAQ section on debugging</a>. |
+ </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 |
+(<a href="http://en.wikipedia.org/wiki/Cross-post" >Wikipedia description</a>). |
+ </li></ul> |
+<h4 id='doNotPost'>What Not to Post</h4> |
+ |
+<ul> |
+ <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></ul><p> |
+ |
+Relevant announcements are welcome, but no more often than once |
+per major release, as a short link to the product's webpage. |
+ </p> </div> |
+<div id='noAnswer' class='section'><h3 id='FAQ2_4'>1.4 Why was my post not answered?</h3><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 <a href="#posting" >section on posting</a> </li> |
+</ul> |
+<p> |
+If it is not one of these, then after a few days consider |
+reposting after checking <a href="http://groups.google.com/group/comp.lang.javascript/topics" >http://groups.google.com/group/comp.lang.javascript/topics</a> |
+for replies. Make sure the post is phrased well, and everything |
+needed to answer is correct, and the subject is appropriate. |
+ </p> </div> |
+<div id='tips' class='section'><h2 id='FAQ2'>2 Language Overview</h2> |
+</div><div id='ecma' class='section'><h3 id='FAQ2_6'>2.1 What is ECMAScript?</h3><p> |
+ <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" >ECMA-262</a> |
+is the international standard that current language implementations |
+(JavaScript™, JScript etc.) are based on. |
+ |
+ </p> <p> |
+ <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" >ECMA-262</a> |
+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 <code>document</code>, <code>window</code>, or <code>ActiveXObject</code>. |
+ </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. |
+<a href="http://www.ecma-international.org/publications/standards/Ecma-327.htm" >http://www.ecma-international.org/publications/standards/Ecma-327.htm</a></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> </div> |
+<div id='jScript' class='section'><h3 id='FAQ2_7'>2.2 What is JScript?</h3><p> |
+ |
+JScript is Microsoft's implementation of ECMAScript. |
+ </p> <p> |
+ |
+Questions that are specific to Microsoft's JScript may also |
+be appropriately asked at: |
+ <a href="news:microsoft.public.scripting.jscript">microsoft.public.scripting.jscript</a>. |
+ </p> </div> |
+<div id='dom' class='section'><h3 id='FAQ2_9'>2.3 What is the Document Object Model (DOM)?</h3><p> |
+ |
+The |
+<dfn>Document Object Model</dfn> (DOM) is a interface-based model for <code>Document</code> |
+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 (<a href="http://msdn.microsoft.com/en-us/library/ms533050(VS.85).aspx" >MSDN</a>, <a href="https://developer.mozilla.org/en/DOM_Client_Object_Cross-Reference" >MDC</a>), |
+such as <code>document.writeln()</code>. |
+ </p> <p> |
+ |
+Also see the section on <a href="#domRef" >DOM and Forms</a>. |
+</p><ul class='linkList'><li><a href="#onlineResources" >c.l.js DOM Resources</a></li> |
+<li><a href="http://www.w3.org/DOM/faq.html" >W3C DOM FAQ</a></li> |
+<li><a href="http://www.w3.org/DOM/" >W3C DOM </a></li> |
+<li><a href="https://developer.mozilla.org/en/Gecko_DOM_Reference/Introduction#What_is_the_DOM.3F" >MDC: What is the DOM?</a></li> |
+</ul> </div> |
+<div id='localization' class='section'><h3 id='FAQ2_10'>2.4 Internationalisation and Localisation in javascript</h3><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 |
+<code>toString()</code> 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 |
+<code>toLocaleString()</code>method which should create a string |
+based on the host's locale. |
+ </p> <p> |
+ |
+ECMAScript 5th Edition introduces limited ISO 8601 capabilities with |
+<code>Date.prototype.toISOString()</code> and new behavior for <code>Date.parse()</code>. |
+</p> </div> |
+<div id='futureEcmaScript' class='section'><h3 id='FAQ2_12'>2.5 What does the future hold for ECMAScript?</h3><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><ul class='linkList'><li><a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" >http://www.ecma-international.org/publications/standards/Ecma-262.htm</a></li> |
+</ul> </div> |
+<div id='ecmascriptResources' class='section'><h2 id='FAQ3'>3 Javascript Resources</h2> |
+</div><div id='books' class='section'><h3 id='FAQ3_1'>3.1 What books are recommended for javascript?</h3><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> |
+<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: <a href="http://oreilly.com/catalog/9780596101992/errata/" >http://oreilly.com/catalog/9780596101992/errata/</a> </li> |
+<li> Discussed in: |
+ |
+<ul> <li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/7283898f77fd2a66/9252aa024e058dea#c5f145ae807c918e" >FAQ Update 9.85 Dated 2007-08-31</a> </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: <a href="http://oreilly.com/catalog/9780596517748/errata/" >http://oreilly.com/catalog/9780596517748/errata/</a> </li> |
+<li> Discussed in: |
+ |
+<ul> <li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/d084d2109f7b4ec7#" >Crockford's 'The Good Parts': a short review</a> </li> |
+<li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/db1e49ab113aa05c/3987eac87ad27966#3987eac87ad27966" >FunctionExpression's and memory consumptions</a> </li> |
+<li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/6a41f7835ee728de/da5ccfc65e2df64a#da5ccfc65e2df64a" >FAQ Topic - What books are recommended for javascript? (2008-12-02)</a> </li> |
+<li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/3a08fb741525ab6d/" >Augmenting functions</a> </li> |
+<li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/bf26be6e63494ee2/acb733a1c35f6ce5#ee9e4ee29e658d5d" >Crockford's JavaScript, The Good Parts (a book review).</a> </li> |
+<li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/df602506ee48b400/e65e00f5cad07676#e65e00f5cad07676" >Closures Explained</a> </li> |
+<li> <a href="http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/acadf1b22b219433/4f69a95607d0b3ae#4f69a95607d0b3ae" >Javascript library development</a> </li> |
+</ul> |
+ </li> |
+</ul> |
+ </li></ul></div> |
+<div id='onlineResources' class='section'><h3 id='FAQ3_2'>3.2 What online resources are available?</h3> |
+<h4 id='ecmaResources'>ECMAScript</h4> |
+ |
+<dl> |
+ <dt> |
+The Official ECMAScript Specification |
+ </dt> |
+ <dd> <a href="[ECMA-262] http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm" >[ECMA-262] http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm</a> </dd> |
+ <dt> |
+[ISO16262] ISO/IEC 16262, Second Edition 2002-06-01 : ISO Standard matching |
+ECMA-262 3rd Edition, with corrections. |
+ </dt> |
+ <dd> <a href="http://standards.iso.org/ittf/PubliclyAvailableStandards/c033835_ISO_IEC_16262_2002(E).zip" >http://standards.iso.org/ittf/PubliclyAvailableStandards/c033835_ISO_IEC_16262_2002(E).zip</a> </dd> |
+ <dt> |
+ [MS-ES3]: Internet Explorer ECMA-262 ECMAScript Language Specification Standards Support |
+ </dt> |
+ <dd> <a href="http://msdn.microsoft.com/en-us/library/ff520996%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ff520996%28VS.85%29.aspx</a> </dd> |
+ <dd> <a href="res/%5BMS-ES3%5D.pdf" >res/%5BMS-ES3%5D.pdf</a> (local alias) </dd> |
+ <dt> |
+ [MS-ES3EX]: Microsoft JScript Extensions to the ECMAScript Language Specification Third Edition |
+ </dt> |
+ <dd> <a href="http://msdn.microsoft.com/en-us/library/ff521046%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ff521046%28VS.85%29.aspx</a> </dd> |
+ <dd> <a href="res/%5BMS-ES3EX%5D.pdf" >res/%5BMS-ES3EX%5D.pdf</a> (local alias) </dd> |
+ <dt> ECMAScript on Wikipedia |
+ </dt> |
+ <dd> <a href="http://en.wikipedia.org/wiki/ECMAScript" >http://en.wikipedia.org/wiki/ECMAScript</a> </dd></dl> |
+<h4 id='domResources'>W3C DOM</h4> |
+ |
+<dl> |
+ <dt> |
+DOM Level 1 ECMAScript Binding |
+ </dt> |
+ <dd> <a href="http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html" >http://www.w3.org/TR/REC-DOM-Level-1/ecma-script-language-binding.html</a> </dd> |
+ <dt> |
+DOM Level 2 ECMAScript Binding |
+ </dt> |
+ <dd> <a href="http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html" >http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html</a> </dd> |
+ <dt> |
+DOM Level 2 Events |
+ </dt> |
+ <dd> <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html" >http://www.w3.org/TR/DOM-Level-2-Events/events.html</a> </dd> |
+ <dt> |
+DOM Level 2 Style |
+ </dt> |
+ <dd> <a href="http://www.w3.org/TR/DOM-Level-2-Style/" >http://www.w3.org/TR/DOM-Level-2-Style/</a> </dd> |
+ <dt> |
+DOM Level 3 ECMAScript Binding |
+ </dt> |
+ <dd> <a href="http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html" >http://www.w3.org/TR/DOM-Level-3-Core/ecma-script-binding.html</a> </dd></dl> |
+<h4 id='browserResources'>Browser Documentation</h4> |
+ |
+<dl> |
+ <dt> |
+Mozilla |
+ </dt> |
+ <dd> JavaScript: |
+<a href="http://developer.mozilla.org/en/docs/JavaScript" >http://developer.mozilla.org/en/docs/JavaScript</a> </dd> |
+ <dd> Gecko DOM Reference: |
+<a href="http://developer.mozilla.org/en/docs/Gecko_DOM_Reference" >http://developer.mozilla.org/en/docs/Gecko_DOM_Reference</a> </dd> |
+ <dt> |
+Microsoft |
+ </dt> |
+ <dd> HTML and DHTML Reference: |
+<a href="http://msdn.microsoft.com/en-us/library/ms533050.aspx" >http://msdn.microsoft.com/en-us/library/ms533050.aspx</a> </dd> |
+ <dd> JScript Language Reference: |
+<a href="http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx</a> </dd> |
+ <dd> Scripting: |
+<a href="http://msdn.microsoft.com/en-us/library/ms950396.aspx" >http://msdn.microsoft.com/en-us/library/ms950396.aspx</a> </dd> |
+ <dt> |
+Opera |
+ </dt> |
+ <dd> Web Specifications Support: |
+<a href="http://www.opera.com/docs/specs/#ecmascript" >http://www.opera.com/docs/specs/#ecmascript</a> </dd> |
+ <dd> JavaScript Support: |
+<a href="http://www.opera.com/docs/specs/js/" >http://www.opera.com/docs/specs/js/</a> </dd> |
+ <dd> ECMAScript Support: |
+<a href="http://www.opera.com/docs/specs/js/ecma" >http://www.opera.com/docs/specs/js/ecma</a> </dd> |
+ <dt> |
+BlackBerry JavaScript Reference |
+ </dt> |
+ <dd> <a href="http://docs.blackberry.com/en/developers/deliverables/11849/" >http://docs.blackberry.com/en/developers/deliverables/11849/</a> </dd> |
+ <dt> |
+ICab InScript |
+ </dt> |
+ <dd> <a href="http://www.muchsoft.com/inscript/" >http://www.muchsoft.com/inscript/</a> </dd> |
+ <dt> Apple Safari </dt> |
+ <dd> Web Content Guide: |
+<a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html" >http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html</a> </dd> |
+ <dt> |
+Webkit |
+ </dt> |
+ <dd> Project Site: <a href="http://webkit.org/" >http://webkit.org/</a> </dd> |
+ <dd> |
+ Wiki: <a href="http://trac.webkit.org/wiki" >http://trac.webkit.org/wiki</a> </dd> |
+ <dd> DOM Reference: |
+<a href="http://developer.apple.com/Mac/library/documentation/AppleApplications/Reference/WebKitDOMRef/index.html#//apple_ref/doc/uid/TP40006089" >http://developer.apple.com/Mac/library/documentation/AppleApplications/Reference/WebKitDOMRef/index.html#//apple_ref/doc/uid/TP40006089</a> </dd> |
+ <dt> |
+Netscape 4 Client-Side JavaScript Reference |
+ </dt> |
+ <dd> <a href="http://docs.sun.com/source/816-6408-10/" >http://docs.sun.com/source/816-6408-10/</a> </dd> |
+ <dt> |
+Archived documentation for MSIE 3.x |
+ </dt> |
+ <dd> <a href="http://members.tripod.com/%7Ehousten/download/" >http://members.tripod.com/%7Ehousten/download/</a> </dd></dl> |
+<h4 id='standaloneImplementations'>Standalone ECMAScript Implementations</h4> |
+ |
+<dl> |
+ <dt> |
+Rhino: An open-source implementation of JavaScript written in Java |
+ </dt> |
+ <dd> <a href="http://www.mozilla.org/rhino/" >http://www.mozilla.org/rhino/</a> </dd> |
+ <dt> |
+Besen IDE: ECMAScript Edition 5 with IDE |
+ </dt> |
+ <dd> <a href="http://besen.sourceforge.net/" >http://besen.sourceforge.net/</a> </dd> |
+ <dt> |
+V8: Google's open source JavaScript engine |
+ </dt> |
+ <dd> <a href="http://code.google.com/p/v8/" >http://code.google.com/p/v8/</a> </dd> |
+ <dt> |
+SpiderMonkey: Mozilla's C implementation of JavaScript |
+ </dt> |
+ <dd> <a href="http://www.mozilla.org/js/spidermonkey/" >http://www.mozilla.org/js/spidermonkey/</a> </dd> |
+ <dt> |
+Digital Mars DMD Script, console and MS Active Script implementation of ECMAScript |
+ </dt> |
+ <dd> <a href="http://www.digitalmars.com/dscript/" >http://www.digitalmars.com/dscript/</a> </dd></dl> |
+<h4 id='nonBrowserResources'>Other ECMAScript Implementations</h4> |
+ |
+<dl> |
+ <dt> |
+Developing Dashboard Widgets: Apple Developer Connection |
+ </dt> |
+ <dd> <a href="http://developer.apple.com/macosx/dashboard.html" >http://developer.apple.com/macosx/dashboard.html</a> </dd> |
+ <dt> |
+Whitebeam Apache Module: Server Side JavaScript in Apache |
+ </dt> |
+ <dd> <a href="http://www.whitebeam.org/" >http://www.whitebeam.org/</a> </dd></dl></div> |
+<div id='libraryResources' class='section'><h3>3.3 Javascript Libraries</h3><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> </div> |
+<div id='functions' class='section'><h2>4 Functions</h2> |
+</div><div id='scope' class='section'><h3>4.1 What is (function(){ /*...*/ })() ?</h3><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><ul class='linkList'><li><a href="http://yura.thinkweb2.com/named-function-expressions/" >http://yura.thinkweb2.com/named-function-expressions/</a></li> |
+<li><a href="notes/closures/" >notes/closures/</a></li> |
+<li><a href="http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses" >http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-parentheses</a></li> |
+</ul> </div> |
+<div id='functionStatement' class='section'><h3>4.2 What is a function statement?</h3><p> |
+ |
+The term |
+<dfn>function statement</dfn> has been widely and wrongly used to |
+describe a <code>FunctionDeclaration</code>. This is misleading because in ECMAScript, |
+a <code>FunctionDeclaration</code> is not a |
+<dfn>Statement</dfn>; there are places in a program |
+where a |
+<dfn>Statement</dfn> is permitted but a <code>FunctionDeclaration</code> 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> |
+<pre> |
+// 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) } |
+</pre> |
+ <p> |
+ |
+Code that uses |
+<dfn>function statement</dfn> has three known interpretations. Some |
+implementations process <code>Fze</code> as a |
+<dfn>Statement</dfn>, in order. Others, including |
+JScript, evaluate <code>Fze</code> upon entering the execution context that it |
+appears in. Yet others, notably DMDScript and default configuration of BESEN, |
+throw a <code>SyntaxError</code>. |
+</p> <p> |
+ |
+For consistent behavior across implementations, <em>do not use function |
+statement</em>; use either <code>FunctionExpression</code> or <code>FunctionDeclaration</code> instead. |
+</p> <p> |
+ |
+Example of <code>FunctionExpression</code> (valid): |
+</p> |
+<pre> |
+var Fze; |
+try { |
+ Fze = function(b,a){return b.unselectable=a}; |
+ /*...*/ |
+} catch(e) { _DumpException(e) } |
+</pre> |
+<p> |
+Example of <code>FunctionDeclaration</code> (valid): |
+</p> |
+<pre> |
+// Program code |
+function aa(b,a){return b.unselectable=a} |
+</pre> |
+ <p> |
+ <!-- |
+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. |
+--></p><ul class='linkList'><li><a href="example/functionStatement.html" >example/functionStatement.html</a></li> |
+<li><a href="https://mail.mozilla.org/pipermail/es-discuss/2008-February/005314.html" >https://mail.mozilla.org/pipermail/es-discuss/2008-February/005314.html</a></li> |
+<li><a href="http://groups.google.com/group/comp.lang.javascript/msg/aa9a32d0c6ae0342" >http://groups.google.com/group/comp.lang.javascript/msg/aa9a32d0c6ae0342</a></li> |
+<li><a href="http://groups.google.com/group/comp.lang.javascript/msg/3987eac87ad27966" >http://groups.google.com/group/comp.lang.javascript/msg/3987eac87ad27966</a></li> |
+<li><a href="http://nanto.asablo.jp/blog/2005/12/10/172622" >http://nanto.asablo.jp/blog/2005/12/10/172622</a></li> |
+<li> (Article in Japanese) |
+</li> |
+</ul> </div> |
+<div id='dates' class='section'><h2>5 Dates</h2> |
+<p> |
+ |
+ISO 8601 defines date and time formats. Some benefits include: |
+</p> |
+<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 <a href="http://www.ietf.org/rfc/rfc3339.txt" >rfc 3339</a> </li></ul><p> |
+ |
+The ISO Extended format for common date is <code>YYYY-MM-DD</code>, and for time is |
+<code>hh:mm:ss</code>. |
+</p> <p> |
+ |
+For an event with an offset from UTC, use <code>YYYY-MM-DDThh:mm:ss±hh:mm</code>. |
+</p> <p> |
+ |
+Never use a local date/time format for a non-local event. Instead, use |
+UTC, as in <code>YYYY-MM-DDThh:mm:ssZ</code> (<code>Z</code> is the only letter suffix). |
+</p> <p> |
+ |
+The <code>T</code> 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 <code>0000</code> is unrecognized by some formats (XML Schema, <code>xs:date</code>). |
+ </p><ul class='linkList'><li><a href="#onlineResources" >ECMA-262 Date.prototype, s. 15.9</a></li> |
+<li><a href="http://www.cl.cam.ac.uk/~mgk25/iso-time.html" >A summary of the international standard date and time notation, by Markus Kuhn</a></li> |
+<li><a href="http://en.wikipedia.org/wiki/ISO_8601" >http://en.wikipedia.org/wiki/ISO_8601</a></li> |
+<li><a href="res/ISO_8601-2004_E.pdf" >ISO 8601:2004(E)</a></li> |
+<li><a href="http://www.w3.org/QA/Tips/iso-date" >W3C QA Tip: Use international date format (ISO)</a></li> |
+<li><a href="http://www.ietf.org/rfc/rfc3339.txt" >RFC 3339, Date and Time on the Internet: Timestamps |
+</a></li> |
+<li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" >http://www.w3.org/TR/xmlschema-2/#dateTime</a></li> |
+</ul> </div><div id='formatDate' class='section'><h3 id='FAQ4_30'>5.1 How do I format a Date object with javascript?</h3><p> |
+ |
+A local <code>Date</code> object where <code>0 <= year <= 9999</code> can be |
+formatted to a common ISO 8601 format <code>YYYY-MM-DD</code> with:- |
+ </p> |
+<pre> |
+ /** 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; |
+ } |
+ </pre> |
+<ul class='linkList'><li><a href="http://www.merlyn.demon.co.uk/js-date9.htm" >http://www.merlyn.demon.co.uk/js-date9.htm</a></li> |
+</ul> </div> |
+<div id='parseDate' class='section'><h3>5.2 How can I create a Date object from a String?</h3><p> |
+ |
+An Extended ISO 8601 local Date format <code>YYYY-MM-DD</code> can be parsed to a |
+Date with the following:- |
+</p> |
+<pre> |
+ /**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; |
+ }</pre> |
+ </div> |
+<div id='numbers' class='section'><h2>6 Numbers</h2> |
+</div><div id='formatNumber' class='section'><h3 id='FAQ4_6'>6.1 How do I format a Number as a String with exactly 2 decimal places?</h3><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: |
+<a href="#binaryNumbers" >Why does simple decimal arithmetic give strange results?</a></p> <p> |
+ |
+The statement <code>n = Math.round(n * 100)/100</code> converts <code>n</code> to a <code>Number</code> value |
+close to a multiple of <code>0.01</code>. However, there are some problems. |
+Converting the number to a string <code>(n + "")</code>, does not give |
+trailing zeroes. Rounding numbers that are very close to <code>x.5</code>, for example, |
+<code>Math.round(0.49999999999999992)</code> results <code>1</code>. |
+ </p> <p> |
+ |
+ECMA-262 3rd Edition introduced <code>Number.prototype.toFixed</code>. |
+There are bugs in JScript 5.8 and below with certain numbers, for example |
+<code>0.007.toFixed(2)</code> incorrectly results <code>0.00</code>. |
+ </p> <p> |
+ </p> |
+<pre> |
+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")); |
+</pre> |
+<ul class='linkList'><li><a href="http://www.merlyn.demon.co.uk/js-round.htm" >http://www.merlyn.demon.co.uk/js-round.htm</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/sstyff0z%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/sstyff0z%28VS.85%29.aspx</a></li> |
+</ul> </div> |
+<div id='binaryNumbers' class='section'><h3 id='FAQ4_7'>6.2 Why does simple decimal arithmetic give strange results?</h3><p> |
+ |
+For example, <code>5 * 1.015</code> does not give exactly |
+<code>5.075</code> and <code>0.06+0.01</code> does |
+not give exactly <code>0.07</code> 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 <code>9e15</code> 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 <a href="#formatNumber" >How do I format a Number as a String with exactly 2 decimal places?</a></p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/7wkd9z69%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/7wkd9z69%28VS.85%29.aspx</a></li> |
+<li><a href="http://www.merlyn.demon.co.uk/js-misc0.htm#DW4" >http://www.merlyn.demon.co.uk/js-misc0.htm#DW4</a></li> |
+</ul> <p> |
+ |
+Otherwise, use <code>Math.round</code> on the results of expressions which |
+should be of integer value. |
+ </p> </div> |
+<div id='parseIntBase' class='section'><h3 id='FAQ4_12'>6.3 Why does K = parseInt('09') set K to 0?</h3><p> |
+ |
+Method <code>parseInt</code> generally needs a second parameter, <code>radix</code>, |
+for the base (from 2 to 36). |
+ </p> <p> |
+ |
+If <code>radix</code> is omitted, the base is determined by the contents of |
+the string. Any string beginning with <code>'0x'</code> or <code>'0X'</code> represents a |
+hexadecimal number. A string beginning with a leading 0 may be parsed as |
+octal (as if <code>raxix</code> were 8), in ECMA-262 Ed 3 (octal digits are <code>0-7</code>). |
+If string <code>'09'</code> is converted to <code>0</code>. |
+ </p> <p> |
+ |
+To force use of a particular base, use the <code>radix</code> |
+parameter: <code>parseInt("09", base)</code>. |
+ |
+ <!-- [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> <p> |
+ </p><ul class='linkList'><li><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt" >http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/toplev.htm#1064173" >http://docs.sun.com/source/816-6408-10/toplev.htm#1064173</a></li> |
+<li><a href="notes/type-conversion/#tcPrIntRx" >notes/type-conversion/#tcPrIntRx</a></li> |
+</ul> </div> |
+<div id='typeConvert' class='section'><h3>6.4 Why does 1+1 equal 11? or How do I convert a string to a number?</h3><p> |
+ |
+Variables are not typed; their values are. The conversion between a |
+string and a number happens automatically. |
+</p> <p> |
+ |
+The addition operator (<code>+</code>) performs concatenation if either operand is a |
+string, thus <code>"1" + 1</code> results <code>"11"</code>. To perform addition, you might need |
+to first convert the string to a number. For example <code>+varname</code> or |
+<code>Number(varname)</code> or <code>parseInt(varname, 10)</code> or |
+<code>parseFloat(varname)</code>. Form control values are strings, as is the result |
+from a <code>prompt</code> dialog. Convert these to numbers before performing |
+addition: <code>+'1' + 1</code> results <code>2</code>. |
+ </p><ul class='linkList'><li> |
+Additional Notes: </li> |
+<li><a href="notes/type-conversion/" >notes/type-conversion/</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/67defydd%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/67defydd%28VS.85%29.aspx</a></li> |
+</ul> </div> |
+<div id='randomNumber' class='section'><h3 id='FAQ4_22'>6.5 How do I generate a random integer from 1 to n?</h3><p> |
+ <code>Math.random()</code> returns a value <code>R</code> such that <code>0 <= R < 1.0</code>; therefore: |
+ </p> |
+<pre> |
+ // positive integer expected |
+ function getRandomNumber(n) { |
+ return Math.floor(n * Math.random()); |
+ } |
+</pre> |
+<p> |
+- gives an evenly distributed random integer in the range from |
+ <code>0</code> to <code>n - 1</code> inclusive; use <code>getRandomNumber(n)+1</code> for <code>1</code> to <code>n</code>. |
+ </p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/41336409%28VS.85%29.aspx</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/math.htm" >http://docs.sun.com/source/816-6408-10/math.htm</a></li> |
+<li> |
+How to Deal and Shuffle, see in: </li> |
+<li><a href="http://www.merlyn.demon.co.uk/js-randm.htm" >http://www.merlyn.demon.co.uk/js-randm.htm</a></li> |
+</ul> </div> |
+<div id='objects' class='section'><h2>7 Objects</h2> |
+</div><div id='nativeObject' class='section'><h3>7.1 What is a native object?</h3><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> |
+<pre> |
+// 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."); |
+ </pre> |
+<p> |
+See also: |
+</p><ul class='linkList'><li><a href="http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/" >http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/</a></li> |
+</ul> </div> |
+<div id='builtInObject' class='section'><h3>7.2 What is a built-in object?</h3><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> |
+<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></dl><p> |
+ |
+ECMA-262 Edition 5 defines also the built-in object <code>JSON</code>. |
+</p> <p> |
+ |
+Nonstandard |
+<dfn>built-in</dfn> objects may include <code>RuntimeObject</code>, |
+<code>String.prototype.link</code>, <code>CollectGarbage</code>, and more. |
+</p> </div> |
+<div id='hostObject' class='section'><h3 id='FAQ2_8'>7.3 What is a host object?</h3><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, <code>XMLHttpRequest</code> might be available, with or |
+without standard or proprietary features or events. Windows Script Host object model |
+has the <code>WScript</code> 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><ul class='linkList'><li><a href="notes/code-guidelines/#hostObjects" >notes/code-guidelines/#hostObjects</a></li> |
+<li><a href="http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting" >http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting</a></li> |
+</ul> </div> |
+<div id='eval' class='section'><h3 id='FAQ4_40'>7.4 When should I use eval?</h3><p> |
+ |
+The <code>eval</code> 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 <code>"12 * 2.54"</code> to a substantial piece of javascript code. |
+</p> <p> |
+ |
+When <code>eval( '{"key" : 42}' )</code> is called, <code>{</code> is interpreted as a block of |
+code instead of an object literal. Hence, the Grouping Operator (parentheses) |
+is used to force <code>eval</code> to interpret the JSON as an object literal: |
+<code>eval( '({"key" : 42})' );</code>. |
+ </p><ul class='linkList'><li><a href="http://json.org/" >http://json.org/</a></li> |
+<li><a href="#propertyAccessAgain" >How do I access a property of an object using a string?</a></li> |
+<li><a href="notes/square-brackets/" >notes/square-brackets/</a></li> |
+</ul> </div> |
+<div id='propertyAccessAgain' class='section'><h3 id='FAQ4_39'>7.5 How do I access a property of an object using a string?</h3><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> |
+<pre> |
+ //dot notation |
+ var bodyElement = document.body; |
+ |
+ //square bracket notation, using an expression |
+ var bodyElement = document["bo"+"dy"];</pre> |
+<ul class='linkList'><li><a href="notes/square-brackets/" >notes/square-brackets/</a></li> |
+</ul> </div> |
+<div id='strings' class='section'><h2>8 Strings and RegExp</h2> |
+</div><div id='trimString' class='section'><h3 id='FAQ4_16'>8.1 How do I trim whitespace?</h3><p> |
+ |
+ECMAScript 5 defines <code>String.prototype.trim</code>. Where not supported, |
+it can be added as a function that uses a |
+<dfn>regular expression</dfn>: |
+</p> |
+<pre> |
+if(!String.prototype.trim) { |
+ String.prototype.trim = function() { |
+ return String(this).replace(/^\s+|\s+$/g, ""); |
+ }; |
+} |
+</pre> |
+<p> |
+Implementations are inconsistent with <code>\s</code>. For example, |
+some implementations, notably JScript 5.8 and Safari 2, do not match <code>\xA0</code> |
+(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> <p> |
+ </p><ul class='linkList'><li><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp" >https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp</a></li> |
+<li><a href="http://thinkweb2.com/projects/prototype/whitespace-deviations/" >http://thinkweb2.com/projects/prototype/whitespace-deviations/</a></li> |
+<li><a href="https://developer.mozilla.org/en/Firefox_3.1_for_developers" >https://developer.mozilla.org/en/Firefox_3.1_for_developers</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/regexp.htm" >http://docs.sun.com/source/816-6408-10/regexp.htm</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/6wzad2b2%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/6wzad2b2%28VS.85%29.aspx</a></li> |
+<li><a href="http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/c7010139217600c3/31092c5eb99625d0?#31092c5eb99625d0" >http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/c7010139217600c3/31092c5eb99625d0?#31092c5eb99625d0</a></li> |
+<li><a href="http://unicode.org/Public/UNIDATA/PropList.txt" >http://unicode.org/Public/UNIDATA/PropList.txt</a></li> |
+</ul> </div> |
+<div id='domRef' class='section'><h2>9 DOM and Forms</h2> |
+</div><div id='formControlAccess' class='section'><h3 id='FAQ4_13'>9.1 How do I get the value of a form control?</h3><p> |
+ |
+In HTML documents, a form may be referred to as a property of the |
+<code>document.forms</code> collection, either by its ordinal index or by name |
+(if the <code>form</code> has a name). A <code>form</code>'s controls may be similarly referenced |
+from its <code>elements</code> collection: |
+</p> |
+<pre> |
+ var frm = document.forms[0]; |
+ var control = frm.elements["elementname"]; |
+</pre> |
+<p> |
+Once a reference to a control is obtained, its (string) <code>value</code> |
+property can be read:- |
+</p> |
+<pre> |
+ var value = control.value; |
+ value = +control.value; //string to number. |
+</pre> |
+<p> |
+Some exceptions would be: |
+</p> <p> |
+ |
+First Exception: Where the control is a <code>SELECT</code> element, and |
+support for older browsers, such as NN4, is required: |
+</p> |
+<pre> |
+ var value = control.options[control.selectedIndex].value; |
+</pre> |
+<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><ul class='linkList'><li><a href="notes/form-access/" >notes/form-access/</a></li> |
+<li><a href="names/" >Unsafe Names for HTML Form Controls</a></li> |
+</ul> <p> |
+ |
+Third Exception: File inputs. Most current browsers do not allow |
+reading of <code>type="file"</code> input elements in a way that is useful. |
+ </p> </div> |
+<div id='propertyAccess' class='section'><h3 id='FAQ4_25'>9.2 My element is named myselect[], how do I access it?</h3><p> |
+ |
+Form controls with any "illegal" characters can be accessed with |
+<code>formref.elements["myselect[]"]</code> - 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><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms537449%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms537449%28VS.85%29.aspx</a></li> |
+<li><a href="https://developer.mozilla.org/en/DOM/form" >https://developer.mozilla.org/en/DOM/form</a></li> |
+<li><a href="notes/form-access/" >notes/form-access/</a></li> |
+</ul> </div> |
+<div id='globalPollution' class='section'><h3 id='FAQ4_41'>9.3 Why doesn't the global variable "divId" always refer to the element with id="divId"?</h3><p> |
+ |
+Microsoft introduced a shortcut that can be used to reference |
+elements which include an <code>id</code> attribute where the |
+<code>id</code> 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 <code>document.getElementById</code> |
+method, which is part of the W3C DOM standard and implemented |
+in modern browsers (including IE from version 5.0). So an |
+element with <code>id="foo"</code> can be referenced |
+with:- |
+ </p> |
+<pre> |
+ var el = document.getElementById("foo"); |
+</pre> |
+<p> |
+Note: make sure not to use the same <code>id</code> twice in the same document |
+and do not give an element a <code>name</code> that matches an <code>id</code> |
+of another in the same document or it will trigger bugs in MSIE <= 7 with |
+<code>document.getElementsByName</code> and <code>document.getElementById</code>. |
+</p><ul class='linkList'><li><a href="https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM#Accessing_Elements_with_the_W3C_DOM |
+" >https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM#Accessing_Elements_with_the_W3C_DOM |
+</a></li> |
+<li><a href="faq_notes/faq_notes.html#FAQN4_41" >faq_notes/faq_notes.html#FAQN4_41</a></li> |
+</ul> </div> |
+<div id='updateContent' class='section'><h3 id='FAQ4_15'>9.4 How do I modify the content of the current page?</h3><p> |
+ |
+Using the non-standard but widely implemented |
+<code>innerHTML</code> property: |
+<code><div id="anID">Some Content</div></code> with script: |
+ </p> |
+<pre> |
+ document.getElementById("anID").innerHTML = |
+ "Some <em>new</em> Content"; |
+</pre> |
+<p> |
+Where <code>"anID"</code> is the (unique on the HTML page) |
+<code>id</code> attribute value of the element to modify. |
+ </p> <p> |
+ |
+All versions of Internet Explorer exhibit problems with innerHTML, including: |
+ </p> |
+<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></ul><p> |
+ |
+If the new content is only text and does not need to replace existing HTML, |
+it is more efficient to modify the <code>data</code> property of a text node. |
+ </p> |
+<pre> |
+ document.getElementById("anID").firstChild.data = "Some new Text"; |
+</pre> |
+ <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 <code>normalize</code> |
+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><ul class='linkList'><li><a href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-FF21A306" >http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-FF21A306</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/cc304097%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/cc304097%28VS.85%29.aspx</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx</a></li> |
+<li><a href="http://developer.mozilla.org/en/Whitespace_in_the_DOM" >http://developer.mozilla.org/en/Whitespace_in_the_DOM</a></li> |
+<li><a href="http://developer.mozilla.org/en/docs/DOM:element.innerHTML" >http://developer.mozilla.org/en/docs/DOM:element.innerHTML</a></li> |
+<li><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm" >http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#html-fragment-serialization-algorithm</a></li> |
+<li> (draft) |
+ </li> |
+</ul> </div> |
+<div id='accessElementBeforeDefined' class='section'><h3>9.5 Why does my code fail to access an element?</h3><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 <code>"load"</code> event to trigger your script. |
+ </p> <p> |
+ |
+Example A: |
+</p> |
+<pre> |
+<div id="snurgle">here</div> |
+<script type="text/javascript"> |
+// Don't forget var. |
+var snurgleEl = document.getElementById("snurgle"); |
+window.alert(snurgleEl.parentNode); |
+</script> |
+</pre> |
+ <p> |
+ |
+Example B: |
+</p> |
+<pre> |
+// In the HEAD. |
+<script type="text/javascript"> |
+window.onload = function(){ |
+ var snurgleEl = document.getElementById("snurgle"); |
+}; |
+</script> |
+</pre> |
+ |
+<h4>Other problems can include:</h4> |
+ |
+<ul> |
+ <li> invalid HTML </li> |
+ <li> two elements with the same <code>name</code> or <code>id</code> </li> |
+ <li> use of an unsafe name: http://jibbering.com/names/ </li></ul></div> |
+<div id='testCookie' class='section'><h3 id='FAQ4_4'>9.6 How can I see in javascript if a web browser accepts cookies?</h3><p> |
+ |
+Write a cookie and read it back and check if it's the same. |
+ </p><ul class='linkList'><li> |
+Additional Notes: |
+</li> |
+<li><a href="http://www.ietf.org/rfc/rfc2965.txt" >http://www.ietf.org/rfc/rfc2965.txt</a></li> |
+<li><a href="http://www.galasoft-lb.ch/myjavascript/consulting/2001012701/" >http://www.galasoft-lb.ch/myjavascript/consulting/2001012701/</a></li> |
+<li><a href="http://www.cookiecentral.com/" >http://www.cookiecentral.com/</a></li> |
+</ul> </div> |
+<div id='windows' class='section'><h2>10 Windows and Frames</h2> |
+<p> |
+ |
+The <code>window</code> object (also referred to by <code>self</code>) is "DOM Level 0". |
+No formal standard for it exists. |
+</p> </div><div id='disableBackButton' class='section'><h3 id='FAQ4_2'>10.1 How can I disable the back button in a web browser?</h3><p> |
+ |
+You can't. The browser's history cannot be modified. However, you |
+can use <code>self.location.replace(url);</code> in some browsers to replace |
+the current page in the history. |
+ </p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms536712%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms536712%28VS.85%29.aspx</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/location.htm#1194240" >http://docs.sun.com/source/816-6408-10/location.htm#1194240</a></li> |
+</ul> </div> |
+<div id='frameRef' class='section'><h3 id='FAQ4_8'>10.2 How do I access a frame's content?</h3><p> |
+ |
+To reference another frame on the <em>same domain</em>: |
+</p> <p> |
+ |
+The |
+<dfn>content window</dfn> of a <code>FRAME</code> or <code>IFRAME</code> can be |
+accessed by the <code>frames</code> collection. |
+</p> <p> |
+ |
+Example: |
+</p> |
+<pre> |
+var fwin; |
+fwin = self.frames[0]; // or: |
+fwin = self.frames["iframeName"]; |
+</pre> |
+ <p> |
+ or, from the <code>IFRAME</code> or <code>FRAME</code> element: |
+</p> |
+<pre> |
+var iframeEl = document.getElementById("myFrame"); |
+var fwin = iframeEl.contentWindow; // Nonstandard, but widely supported. |
+var fdoc = iframeEl.contentDocument; // DOM2 HTML Standard. |
+</pre> |
+ <p> |
+ |
+A global identifier <code>moomin</code> in the the iframe's |
+<dfn>content window</dfn> |
+is accessed as <code>fwin.moomin</code>. |
+ </p> <p> |
+ |
+To communicate between frames on <em>different</em> domains: |
+</p> <p> |
+ |
+Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use |
+<code>window.postMessage( message[, port], otherDomain);</code>. |
+</p> <p> |
+ |
+Example: |
+<a href="http://jibbering.com/faq/example/postMessage.html" >http://jibbering.com/faq/example/postMessage.html</a></p> <p> |
+ |
+Where <code>window.postMessage</code> is not supported, the <code>window.name</code> property |
+can be set on the other window, which can poll for updates to that |
+property using <code>setInterval(checkWinName, 100);</code> where <code>checkWinName</code> |
+is a function that polls to check the value of |
+<code>self.name</code>. |
+</p><ul class='linkList'><li><a href="http://en.wikipedia.org/wiki/Same_origin_policy" >http://en.wikipedia.org/wiki/Same_origin_policy</a></li> |
+<li><a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html" >http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html</a></li> |
+<li><a href="https://developer.mozilla.org/en/DOM/window.postMessage" >https://developer.mozilla.org/en/DOM/window.postMessage</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx" >http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx</a></li> |
+</ul> </div> |
+<div id='getWindowSize' class='section'><h3 id='FAQ4_9'>10.3 How do I find the size of the window?</h3><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> |
+<pre> |
+ window.innerWidth |
+ document.clientWidth |
+ document.documentElement.clientWidth |
+ document.body.clientWidth |
+</pre> |
+<p> |
+ |
+Of the browsers that have an <code>innerWidth</code> property, most |
+include scrollbar dimensions. Some versions of KHTML browsers |
+(including Safari 2) do <em>not</em> include scrollbar width. |
+ </p> <p> |
+ |
+The <code>window.inner*</code> properties are unreliable and not |
+useful here. We don't want scrollbar dimensions included. |
+</p> |
+<pre> document.clientWidth</pre> |
+ <p> |
+ |
+Certain versions of KHTML, including Safari 2, have |
+<code>document.clientHeight</code> and <code>document.clientWidth</code> |
+properties. Where supported, these rare properties accurately |
+return the height and width of the viewport, without including |
+scrollbar dimensions. |
+ </p> |
+<pre> |
+ document.documentElement.clientWidth |
+ document.body.clientWidth |
+</pre> |
+<p> |
+MSHTML (Trident), Firefox (Gecko), Opera (Presto), and Safari |
+(Webkit) all support <code>clientHeight</code> on <code>document.body</code> |
+and <code>document.documentElement</code>. The difficulty is figuring out |
+which one is reliable. In other words which object to get the |
+<code>clientHeight</code> property from:<code>documentElement</code> or <code>body</code>? |
+ </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 <code>body.clientHeight</code> |
+(except for in Safari 2). |
+ |
+ </p> |
+<pre> document.body.clientHeight</pre> |
+<p> |
+ |
+Some environments will return the viewport height. Others will |
+return <code>0</code>. Yet others will return the <code>clientHeight</code> of |
+the <code>BODY</code> element. |
+ |
+ </p> |
+<pre> document.documentElement.clientHeight</pre> |
+<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 <code>clientHeight</code> |
+of the <code>html</code> <em>element</em>. (Oddly, Opera <= 9.25 |
+in standards mode returns the width of the viewport for |
+<code>documentElement.clientWidth</code>). |
+ </p> <p> |
+ |
+With the exception of Safari 2, <code>body.clientHeight</code> is reliable |
+where <code>documentElement.clientHeight</code> is found to be unreliable. |
+For example, in Safari 3+, Opera, and Mozilla, all in quirks mode, |
+<code>document.documentElement.clientHeight</code> returns the <code>clientHeight</code> |
+of the <code>html</code> element (this may seem unsurprising but |
+it is not what we want). |
+ </p> <p> |
+ |
+Conversely, <code>document.body.clientHeight</code> will return |
+the height of the viewport in most cases where |
+<code>document.documentElement.clientHeight</code> does not. An exception |
+to that is Safari 2, where <code>documentElement.clientHeight</code> |
+and <code>body.clientHeight</code> 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 <code>document.clientHeight</code> is reliable where |
+(rarely) supported, and since browsers that support this property |
+don't return the viewport dimensions from |
+<code>document.body.clientHeight</code> or |
+<code>document.documentElement.clientHeight</code>, this should be the |
+very first condition: |
+ |
+ </p> |
+<pre> |
+ // Safari 2 uses document.clientWidth (default). |
+ if(typeof document.clientWidth == "number") { |
+ // use document.clientWidth. |
+ } |
+</pre> |
+<p> |
+ |
+The next strategy is to determine if |
+<code>document.documentElement.clientHeight</code> property is unreliable. |
+It is deemed "unreliable" when it is either <code>0</code> or taller |
+than the viewport. |
+ </p> <p> |
+ |
+ Determining if <code>documentElement.clientHeight</code> is <code>0</code> is easy. |
+ The result is stored in a variable <code>IS_BODY_ACTING_ROOT</code>. |
+ |
+ </p> |
+<pre> |
+ var docEl = document.documentElement, |
+ IS_BODY_ACTING_ROOT = docEl && docEl.clientHeight === 0; |
+ docEl = null; |
+</pre> |
+<p> |
+ |
+To determine if <code>documentElement.clientHeight</code> returns |
+a value taller than the viewport, we need a |
+<dfn>Capability Test.</dfn></p> <p> |
+ |
+If we can force <code>documentElement</code> to be very tall |
+(taller than a normal viewport) we can then check to see if |
+<code>documentElement.clientHeight</code> returns that "very tall" number. |
+If it does, then it is unreliable. |
+ </p> <p> |
+ |
+We can force <code>documentElement</code> to be taller than the viewport |
+(or any "normal" viewport) by adding a <code>div</code> to the <code>body</code>, |
+give that <code>div</code> a height larger than any normal monitor, |
+and then check to see if <code>documentElement.clientHeight</code> is |
+that high (or "almost" that high, to account for <code>documentElement</code> |
+having a border). |
+ |
+ </p> |
+<pre> |
+ // 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; |
+ } |
+</pre> |
+<p> |
+ |
+We can use this function to see if we should use |
+<code>body.clientHeight</code>, instead. (but only after checking if |
+<code>document.clientHeight</code> is supported). |
+ |
+ </p> |
+<pre> |
+ // 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. |
+ } |
+</pre> |
+<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 <code>APE.dom.getViewportDimensions</code>. |
+Source code: |
+<a href="http://dhtmlkitchen.com/ape/build/dom/viewport-f.js" >http://dhtmlkitchen.com/ape/build/dom/viewport-f.js</a>. |
+APE is publicly released under Academic Free License. |
+APE home: <a href="http://dhtmlkitchen.com/ape/" >http://dhtmlkitchen.com/ape/</a>. |
+ </p> <p> |
+ |
+Note: The dimensions cannot be determined accurately until after |
+the document has finished loading. |
+</p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms533566%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms533566%28VS.85%29.aspx</a></li> |
+<li><a href="http://developer.mozilla.org/en/DOM/window.innerWidth" >http://developer.mozilla.org/en/DOM/window.innerWidth</a></li> |
+<li><a href="http://dev.opera.com/articles/view/using-capability-detection/" >http://dev.opera.com/articles/view/using-capability-detection/</a></li> |
+</ul> </div> |
+<div id='isWindowOpen' class='section'><h3 id='FAQ4_10'>10.4 How do I check to see if a child window is open, before opening another?</h3><p> |
+ </p> |
+<pre> |
+ var myWin; |
+ function openWin(aURL) { |
+ if (!myWin || myWin.closed ) { |
+ myWin = window.open(aURL,'myWin'); |
+ } else { |
+ myWin.location.href = aURL; |
+ myWin.focus(); |
+ } |
+ }</pre> |
+<p> |
+Popup windows cause usability problems and are generally best avoided. |
+</p><ul class='linkList'><li><a href="https://developer.mozilla.org/en/DOM:window.open" >https://developer.mozilla.org/en/DOM:window.open</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms533574%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms533574%28VS.85%29.aspx</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/window.htm#1201877" >http://docs.sun.com/source/816-6408-10/window.htm#1201877</a></li> |
+<li><a href="http://www.useit.com/alertbox/990530.html" >http://www.useit.com/alertbox/990530.html</a></li> |
+</ul> </div> |
+<div id='printFrame' class='section'><h3 id='FAQ4_11'>10.5 Why does framename.print() not print the correct frame in IE?</h3><p> |
+ |
+IE prints the frame that has focus when you call the print |
+method <code>frameref.focus();frameref.print();</code></p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms976105.aspx" >http://msdn.microsoft.com/en-us/library/ms976105.aspx</a></li> |
+</ul> </div> |
+<div id='windowClose' class='section'><h3 id='FAQ4_14'>10.6 How do I close a window and why does it not work on the first one?</h3><p> |
+ |
+If a window was opened by javascript, then it can be closed |
+without confirmation by using <code>windowRef.close()</code>. |
+</p> <p> |
+ |
+Before calling <code>windowRef.close()</code> (or other <code>window</code> methods), make |
+sure the window reference is not null and its <code>closed</code> property is <code>false</code>. |
+</p> <p> |
+ |
+Popup windows cause usability problems and are generally best avoided. |
+</p> <p> |
+ </p><ul class='linkList'><li><a href="http://www.useit.com/alertbox/990530.html" >http://www.useit.com/alertbox/990530.html</a></li> |
+<li><a href="#isWindowOpen " >#isWindowOpen </a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms536367%28VS.85%29.aspx</a></li> |
+<li><a href="https://developer.mozilla.org/en/DOM/window.close#Description" >https://developer.mozilla.org/en/DOM/window.close#Description</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/window.htm#1201822" >http://docs.sun.com/source/816-6408-10/window.htm#1201822</a></li> |
+</ul> </div> |
+<div id='permissionDenied' class='section'><h3 id='FAQ4_19'>10.7 Why do I get permission denied when accessing a frame/window?</h3><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><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms533028%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms533028%28VS.85%29.aspx</a></li> |
+<li><a href="https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript" >https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript</a></li> |
+</ul> </div> |
+<div id='setTimeout' class='section'><h3 id='FAQ4_20'>10.8 How do I make a 10 second delay?</h3><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 <code>setTimeout</code> and <code>setInterval</code> functions |
+to facilitate timed delays. The delay before calling <code>getSnork</code> may |
+exceed the second parameter to <code>setTimeout</code> and <code>setInterval</code> |
+due to implementation differences among browsers. |
+ </p> <p> |
+ |
+ To call the function <code>getSnork</code>, approximately 10 seconds |
+ after the function <code>getMoomin()</code> completes, you would do this: |
+ </p> |
+<pre> |
+ getMoomin(); |
+ setTimeout(getSnork, 10000); |
+</pre> |
+<p> |
+Script execution is not stopped, and adding <code>getSnufkin()</code> after the |
+<code>setTimeout</code> line would immediately execute the function <code>getSnufkin</code> |
+before <code>getSnork</code>. |
+ </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 <code>WScript.Sleep()</code> in the Windows Script Host. |
+</p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms536753%28VS.85%29.aspx</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/window.htm#1203758" >http://docs.sun.com/source/816-6408-10/window.htm#1203758</a></li> |
+<li><a href="http://en.wikipedia.org/wiki/Event-driven_programming" >http://en.wikipedia.org/wiki/Event-driven_programming</a></li> |
+<li><a href="faq_notes/misc.html#mtSetTI" >faq_notes/misc.html#mtSetTI</a></li> |
+</ul> </div> |
+<div id='printSettings' class='section'><h3 id='FAQ4_23'>10.9 How do I change print settings for window.print()?</h3><p> |
+ |
+In a normal security environment, you can't change anything. |
+</p> <p> |
+ |
+Print Stylesheet rules provide options. |
+</p> <p> |
+ For IE, <code>ActiveX</code> or Plugin ScriptX and |
+Neptune from Meadroid to give you more control for Windows |
+versions of Internet Explorer, Netscape, and Opera. |
+</p><ul class='linkList'><li><a href="http://www.meadroid.com/scriptx/" >http://www.meadroid.com/scriptx/</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms976105.aspx" >http://msdn.microsoft.com/en-us/library/ms976105.aspx</a></li> |
+</ul> </div> |
+<div id='changeBrowserDialog' class='section'><h3 id='FAQ4_28'>10.10 How do I change the confirm box to say yes/no or default to cancel?</h3><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> </div> |
+<div id='fileDownload' class='section'><h3 id='FAQ4_33'>10.11 How do I prompt a "Save As" dialog for an accepted mime type?</h3><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:- |
+<code>Content-Disposition: attachment; filename=filename.ext</code></p><ul class='linkList'><li><a href="http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html" >http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html</a></li> |
+<li><a href="http://support.microsoft.com/kb/q260519/" >http://support.microsoft.com/kb/q260519/</a></li> |
+</ul> </div> |
+<div id='modifyChrome' class='section'><h3 id='FAQ4_36'>10.12 How do I modify the current browser window?</h3><p> |
+ |
+In a default security environment you are very limited in how much |
+you can modify the current browser window. You can use |
+<code>window.resizeTo</code> or <code>window.moveTo</code> to resize or move a |
+window respectively, but that is it. Normally you can only |
+suggest chrome changes in a <code>window.open</code>. |
+</p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/ms536651%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms536651%28VS.85%29.aspx</a></li> |
+<li><a href="https://developer.mozilla.org/en/DOM:window.open" >https://developer.mozilla.org/en/DOM:window.open</a></li> |
+</ul> </div> |
+<div id='target' class='section'><h3 id='FAQ4_37'>10.13 How do I POST a form to a new window?</h3><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> |
+<pre> |
+ <form action="" method="post" |
+ target="wndname" onsubmit="window.open('',this.target);return true;"></pre> |
+<ul class='linkList'><li><a href="http://www.htmlhelp.com/reference/html40/forms/form.html" >http://www.htmlhelp.com/reference/html40/forms/form.html</a></li> |
+</ul> </div> |
+<div id='openWindow' class='section'><h3 id='FAQ4_42'>10.14 How do I open a new window with javascript?</h3><p> |
+ |
+New windows can be opened on browsers that support the |
+<code>window.open</code> function and are not subject to the action of any |
+pop-up blocking mechanism with code such as:- |
+ </p> |
+<pre> |
+ var wRef; |
+ if(window.open){ |
+ wRef = window.open("http://example.com/page.html","windowName"); |
+ }</pre> |
+<ul class='linkList'><li><a href="https://developer.mozilla.org/en/DOM:window.open" >https://developer.mozilla.org/en/DOM:window.open</a></li> |
+<li><a href="http://www.infimum.dk/HTML/JSwindows.html" >http://www.infimum.dk/HTML/JSwindows.html</a></li> |
+</ul> </div> |
+<div id='ajaxRef' class='section'><h2>11 Ajax and Server Communication</h2> |
+</div><div id='ajax' class='section'><h3 id='FAQ4_44'>11.1 What is Ajax?</h3><p> |
+ |
+<dfn title = 'Asynchronous JavaScript and XML'>Ajax</dfn> |
+is shorthand for Asynchronous JavaScript and XML. The technology is |
+based on the <code>XMLHttpRequest</code> Object. At its simplest, |
+it is the sending/retrieving of new data from the server without |
+changing or reloading the window location. |
+</p><ul class='linkList'><li> |
+Mozilla Documentation: |
+</li> |
+<li><a href="http://developer.mozilla.org/en/docs/XMLHttpRequest" >http://developer.mozilla.org/en/docs/XMLHttpRequest</a></li> |
+<li> |
+MSDN Documention: |
+</li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms535874%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms535874%28VS.85%29.aspx</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms759148%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms759148%28VS.85%29.aspx</a></li> |
+<li> |
+Libraries and Tutorial Sites: |
+</li> |
+<li><a href="http://jibbering.com/2002/4/httprequest.html" >http://jibbering.com/2002/4/httprequest.html</a></li> |
+<li><a href="http://www.ajaxtoolbox.com/" >http://www.ajaxtoolbox.com/</a></li> |
+</ul> </div> |
+<div id='downloadPage' class='section'><h3 id='FAQ4_38'>11.2 How do I download a page to a variable?</h3><p> |
+ |
+Although <code>XMLHttpRequest</code> 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><ul class='linkList'><li><a href="http://jibbering.com/2002/4/httprequest.html" >http://jibbering.com/2002/4/httprequest.html</a></li> |
+<li><a href="http://www.ajaxtoolbox.com/" >http://www.ajaxtoolbox.com/</a></li> |
+</ul> </div> |
+<div id='getServerVariable' class='section'><h3 id='FAQ4_18'>11.3 How do I get a jsp/php variable into client-side javascript?</h3><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: <code>org.apache.commons.lang.StringEscapeUtils</code>: |
+ </p> |
+<pre> |
+var jsVar = "<%= StringEscapeUtils.escapeJavaScript(str) %>"; |
+</pre> |
+ <p> |
+ PHP example using <code>addcslashes</code>: |
+</p> |
+<pre> |
+var jsVar = "<?php echo addcslashes($str,"\\\'\"\n\r"); ?>"; |
+</pre> |
+<ul class='linkList'><li><a href="example/addcslashes.php" >example/addcslashes.php</a></li> |
+<li><a href="http://php.net/manual/en/function.addcslashes.php" >http://php.net/manual/en/function.addcslashes.php</a></li> |
+<li><a href="http://commons.apache.org/lang/" >http://commons.apache.org/lang/</a></li> |
+</ul> </div> |
+<div id='sessionExpired' class='section'><h3 id='FAQ4_29'>11.4 How do I log-out a user when they leave my site?</h3><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> |
+<p> |
+The URL below has more information. |
+</p><ul class='linkList'><li><a href="http://groups.google.com/groups?selm=BlmZ7.55691%244x4.7344316%40news2-win.server.ntlworld.com" >http://groups.google.com/groups?selm=BlmZ7.55691%244x4.7344316%40news2-win.server.ntlworld.com</a></li> |
+</ul> </div> |
+<div id='runServerScript' class='section'><h3 id='FAQ4_34'>11.5 How do I run a server side script?</h3><p> |
+ |
+You trigger a server-side script by sending an HTTP request. |
+This can be achieved by setting the <code>src</code> of an <code>img</code>, |
+<code>Image</code>, <code>frame</code>, or <code>iframe</code>, 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> <p> |
+ </p> |
+<pre> |
+ var dummyImage = new Image(); |
+ dummyImage.src = "scriptURL.asp?param=" + varName; |
+</pre> |
+ <p> |
+ |
+Mozilla, Opera 7.6+, Safari 1.2+, and Windows IE 7 |
+provide the <code>XMLHttpRequest</code> object |
+(Windows IE versions 5+, provides ActiveX to acheive an analagous |
+effect). <code>XMLHttpRequest</code> can send HTTP requests to |
+the server, and provides access the <code>responseText</code> or <code>responseXML</code> |
+(when the response is XML), and HTTP header information. |
+</p><ul class='linkList'><li><a href="http://jibbering.com/2002/4/httprequest.html" >http://jibbering.com/2002/4/httprequest.html</a></li> |
+<li><a href="http://www.w3.org/TR/XMLHttpRequest/" >http://www.w3.org/TR/XMLHttpRequest/</a></li> |
+<li><a href="http://developer.mozilla.org/en/XMLHttpRequest" >http://developer.mozilla.org/en/XMLHttpRequest</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms537505(VS.85).aspx" >http://msdn.microsoft.com/en-us/library/ms537505(VS.85).aspx</a></li> |
+</ul> </div> |
+<div id='noCache' class='section'><h3 id='FAQ4_17'>11.6 How do I force a reload from the server/prevent caching?</h3><p> |
+ |
+To reload a page, use <code>location.reload()</code>. 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: |
+<code>location.replace(location.href+'?d='+new Date().valueOf())</code> |
+If the <code>location.href</code> already contains a query String, use: |
+<code>location.replace(location.href+'&d='+new Date().valueOf())</code></p><ul class='linkList'><li><a href="http://www.mnot.net/cache_docs/" >http://www.mnot.net/cache_docs/</a></li> |
+<li><a href="http://docs.sun.com/source/816-6408-10/date.htm" >http://docs.sun.com/source/816-6408-10/date.htm</a></li> |
+</ul> </div> |
+<div id='ajaxCache' class='section'><h3 id='FAQ4_45'>11.7 Why is my Ajax page not updated properly when using an HTTP GET request in Internet Explorer?</h3><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 <code>EXPIRES</code> and/or <code>CACHE-CONTROL</code> response header(s) |
+ with a past date or use a unique query string. |
+ </p> |
+<pre> |
+ req.open("GET", "/example.jsp?date=" + (+new Date), true); |
+</pre> |
+<p> |
+ |
+Always use the appropriate HTTP method. Do not use <code>POST</code> |
+to prevent caching. See <a href="http://www.faqs.org/rfcs/rfc2616.html" >RFC 2616</a>. |
+ |
+</p><ul class='linkList'><li><a href="http://www.mnot.net/cache_docs/#EXPIRES" >http://www.mnot.net/cache_docs/#EXPIRES</a></li> |
+<li><a href="http://www.mnot.net/javascript/xmlhttprequest/cache.html " >http://www.mnot.net/javascript/xmlhttprequest/cache.html </a></li> |
+</ul> </div> |
+<div id='debugging' class='section'><h2>12 Debugging</h2> |
+</div><div id='javascriptErrors' class='section'><h3 id='FAQ4_43'>12.1 How do I get my browser to report javascript errors?</h3><p> |
+ |
+There are debugging tools for many browsers. Learn to use them all. |
+ </p> |
+<dl> |
+ <dt> Windows </dt> |
+ <dd> <a href="http://www.fiddlertool.com/fiddler/" >Fiddler</a>. |
+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, |
+<code>Tools</code>, <code>Internet Options</code>, <code>Advanced</code>, and uncheck |
+<code>Disable Script Debugging</code>. After enabling Script Debugging, |
+a <code>Script Debugger</code> option will appear in the <code>View</code> menu. </dd> |
+ <dd> <a href="http://www.my-debugbar.com/wiki/IETester/HomePage" >IETester</a> for testing IE 5.5- IE8. </dd> |
+ <dd> <a href="http://www.my-debugbar.com/wiki/CompanionJS/HomePage" >CompanionJS</a><code>console</code> 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 <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=2F465BE0-94FD-4569-B3C4-DFFDF19CCD99&displaylang=en" >Microsoft Script Debugger</a> may be somewhat helpful. |
+ </dd> |
+ <dd> <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en" >Internet Explorer Developer Toolbar</a> </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, <code>Internet Options</code>, <code>Advanced</code>, deselect <code>"Disable Script Debugging"</code>, |
+select <code>"Display a notification ..."</code>. |
+ </dd> |
+ <dt> Firefox </dt> |
+ <dd> <code>Tools > Error console</code> (<code>Ctrl</code> + <code>Shift</code> + <code>j</code>). |
+ </dd> |
+ <dd> <a href="http://getfirebug.com/" >Firebug</a> </dd> |
+ <dd> <a href="https://addons.mozilla.org/en-US/firefox/addon/5369" >YSlow</a>. |
+YSlow analyzes web pages and tells you why they're slow |
+based on Yahoo's rules for high performance web sites. |
+ </dd> |
+ <dd> <a href="https://addons.mozilla.org/en-US/firefox/addon/1743" >Lori</a> |
+<dfn>Lori</dfn> or Life-of-request info, is useful for troubleshooting |
+server response and page load time. |
+ </dd> |
+ <dd> <a href="https://addons.mozilla.org/en-US/firefox/addon/60" >Web Developer Toolbar</a>. |
+ </dd> |
+ <dd> <a href="https://addons.mozilla.org/en-US/firefox/addon/1201" >Cookie Watcher</a>. |
+ </dd> |
+ <dd> <a href="https://addons.mozilla.org/en-US/firefox/addon/1192" >XPather</a>. |
+XPath generator, editor and inspector. |
+ </dd> |
+ <dt> Opera </dt> |
+ <dd> |
+Tools > Advanced > Error console |
+ </dd> |
+ <dd> <a href="http://dev.opera.com/articles/view/introduction-to-opera-dragonfly/" >Introduction to Opera Dragonfly</a> </dd> |
+ <dt> Safari </dt> |
+ <dd> |
+To display the <code>Develop</code> menu in Safari 3.1 or higher, select |
+the checkbox labeled "Show Develop menu in menu bar" in |
+Safari's <code>Advanced</code> Preferences panel. |
+ </dd> |
+ <dd> <a href="http://trac.webkit.org/wiki/Web%20Inspector " >Safari Web Inspector</a> </dd> |
+ <dt> Chrome </dt> |
+ <dd> |
+JavaScript Console: click the <code>Page</code> menu icon and select |
+<code>Developer > JavaScript Console</code>. 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 <code>Page</code> menu icon > <code>Developer</code> |
+> Debug JavaScript, the debugger provides a command prompt from which you |
+can set breakpoints, backtrace, and more. Type <code>help</code> at the debugger |
+command line to get started. |
+ </dd> |
+ <dd> |
+<ul> <li> <a href="http://www.google.com/chrome/intl/en/webmasters-faq.html#jsexec" >Google Chrome Script Debugging</a> </li> |
+<li> <a href="http://blog.chromium.org/2009/06/developer-tools-for-google-chrome.html" >Developer Tools for Google Chrome</a> </li> |
+<li> <a href="http://blog.chromium.org/2009/08/google-chrome-developer-tools-for.html" >Tools for Eclipse Users</a> </li> |
+</ul> |
+ </dd> |
+ <dt> Mac IE </dt> |
+ <dd> |
+Use the Preferences dialog. |
+ </dd></dl></div> |
+<div id='doNotTry' class='section'><h2>13 Things not to attempt in a browser</h2> |
+</div><div id='detectBrowser' class='section'><h3 id='FAQ4_26'>13.1 How do I detect Opera/Safari/IE?</h3><p> |
+ |
+The short answer: <em>Don't do that</em>. |
+ </p> <p> |
+ |
+The <code>navigator</code> |
+<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 <code>navigator.userAgent</code> to any value. For |
+example, Firefox, (type <code>about:config</code> and search <code>useragent</code> |
+or Safari, <code>Develop > User Agent > Other...</code>, 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. |
+<a href="http://dev.opera.com/articles/view/using-capability-detection/" >Capability detection</a> 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> |
+<pre> |
+/** |
+ * 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; |
+}</pre> |
+<ul class='linkList'><li><a href="notes/detect-browser/" >notes/detect-browser/</a></li> |
+<li><a href="http://dev.opera.com/articles/view/using-capability-detection/" >http://dev.opera.com/articles/view/using-capability-detection/</a></li> |
+<li><a href="http://developer.apple.com/internet/webcontent/objectdetection.html" >http://developer.apple.com/internet/webcontent/objectdetection.html</a></li> |
+<li><a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43" >http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43</a></li> |
+</ul> </div> |
+<div id='preventAccess' class='section'><h3 id='FAQ4_5'>13.2 How can I prevent access to a web page by using javascript?</h3><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> </div> |
+<div id='hideSource' class='section'><h3 id='FAQ4_1'>13.3 How do I protect my javascript code?</h3><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><ul class='linkList'><li> |
+ Your code is likely protected under copyright laws. See: |
+ </li> |
+<li><a href="http://www.wipo.int/about-ip/en/copyright.html" >http://www.wipo.int/about-ip/en/copyright.html</a></li> |
+<li><a href="http://webdesign.about.com/od/copyright/Copyright_Issues_on_the_Web_Intellectual_Property.htm" >http://webdesign.about.com/od/copyright/Copyright_Issues_on_the_Web_Intellectual_Property.htm</a></li> |
+</ul> </div> |
+<div id='disableRightClick' class='section'><h3 id='FAQ4_27'>13.4 How do I suppress a context menu (right-click menu)?</h3><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 <code>oncontextmenu</code> event handler. |
+</p> |
+<pre> |
+document.oncontextmenu = function() { |
+ return false; |
+}; |
+</pre> |
+<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><ul class='linkList'><li><a href="http://en.wikipedia.org/wiki/Context_menu" >http://en.wikipedia.org/wiki/Context_menu</a></li> |
+<li><a href="http://kb.mozillazine.org/Ui.click_hold_context_menus" >http://kb.mozillazine.org/Ui.click_hold_context_menus</a></li> |
+<li><a href="http://support.microsoft.com/kb/823057" >http://support.microsoft.com/kb/823057</a></li> |
+<li><a href="http://stackoverflow.com/questions/1870880/opera-custom-context-menu-picking-up-the-right-click/1902730#1902730" >http://stackoverflow.com/questions/1870880/opera-custom-context-menu-picking-up-the-right-click/1902730#1902730</a></li> |
+<li><a href="http://support.mozilla.com/en-US/kb/Javascript#Advanced_JavaScript_settings" >http://support.mozilla.com/en-US/kb/Javascript#Advanced_JavaScript_settings</a></li> |
+<li><a href="http://msdn.microsoft.com/en-us/library/ms536914%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/ms536914%28VS.85%29.aspx</a></li> |
+</ul> </div> |
+<div id='readFile' class='section'><h3 id='FAQ4_3'>13.5 How can I access the client-side filesystem?</h3><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 <a href="http://groups.google.com/group/comp.lang.javascript/topics" >Google Groups archives</a> |
+for previous posts on the subject. |
+ </p><ul class='linkList'><li><a href="http://msdn.microsoft.com/en-us/library/z9ty6h50%28VS.85%29.aspx" >http://msdn.microsoft.com/en-us/library/z9ty6h50%28VS.85%29.aspx</a></li> |
+<li><a href="http://www.javaworld.com/javaworld/jw-10-1998/jw-10-apptowin32.html" >http://www.javaworld.com/javaworld/jw-10-1998/jw-10-apptowin32.html</a></li> |
+</ul> </div> |
+<div id='javascriptURI' class='section'><h3 id='FAQ4_24'>13.6 I have <a href="javascript:somefunction()"> what ... ?</h3><p> |
+ |
+Whatever the rest of your question, this is generally a very bad idea. |
+The <code>javascript:</code> pseudo protocol was designed to replace the |
+current document with the value that is returned from the expression. |
+For example: |
+ </p> |
+<pre> |
+ <a href="javascript:'&lt;h1&gt;' + document.lastModified + '&lt;/h1&gt;'">lastModified</a> |
+</pre> |
+<p> |
+will result in replacing the current document with the value |
+returned from <code>document.lastModified</code>, wrapped in an <code><h1></code> |
+tag. |
+ </p> <p> |
+ |
+When the expression used evaluates to an <code>undefined</code> 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 <code>META</code> refresh, assignment to <code>location.href</code>, and image |
+swaps fail. |
+ </p> <p> |
+ |
+It is also possible for IE to be configured such that it supports |
+javascript but not the <code>javascript:</code> protocol. This results |
+in the user seeing a protocol error for <code>javascript:</code> URIs. |
+ </p> <p> |
+ |
+The <code>javascript:</code> pseudo protocol creates accessibility and |
+usability problems. It provides no fallback for when the script is not |
+supported. |
+ </p> <p> |
+ |
+Instead, use |
+<code><a href="something.html" onclick="somefunction();return false"></code> |
+where <code>something.html</code> is a meaningful alternative. Alternatively, |
+attach the <code>click</code> callback using an event registry. |
+ </p><ul class='linkList'><li><a href="example/jsuri/" >example/jsuri/</a></li> |
+<li><a href="http://groups.google.com/group/comp.lang.javascript/msg/f665cfca3b619692" >Set/Navigate to a Location</a></li> |
+<li><a href="http://www.useit.com/alertbox/20021223.html" >Top Ten Web-Design Mistakes of 2002</a></li> |
+</ul> </div> |
+<div id='comments' class='section'><h2 id='FAQ5'>14 Comments and Suggestions</h2> |
+<p> |
+ |
+The FAQ uses the stylesheet <a href="faq.css" >faq.css</a> and is generated |
+from the xml source <a href="index.xml" >index.xml</a> by the windows script |
+host script <a href="process.wsf" >process.wsf</a> which also checks the links. |
+ </p> </div><div id='FAQENTRY' class='section'><h3 id='FAQ5_1'>14.1 Why do some posts have <FAQENTRY> in them?</h3><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 the FAQ. It should |
+also not be literally quoted in replies, instead it should be |
+partly obscured as, e.g. <FAQ**TRY> or similar. |
+ </p> </div> |
+<div id='makeSuggestion' class='section'><h3 id='FAQ5_2'>14.2 How do I make a suggestion?</h3><p> |
+ |
+The FAQ is currently lacking a maintainer, please contact Jim Ley |
+(jim.ley@gmail.com) if you wish to take it over, you will need to |
+be in good standing in the group and trustworthy to have access to the |
+server. All comments, suggestions, and especially corrections are |
+welcome. |
+ </p> </div> |
+<!--<script src='FAQReader.js' type='text/javascript'></script>--></body> |
+</html> |
+ |
/cljs/backup/index.html |
Property changes: |
Added: svn:mime-type |
## -0,0 +1 ## |
+text/plain |
\ No newline at end of property |
Index: cljs/backup/process.wsf |
=================================================================== |
--- cljs/backup/process.wsf (nonexistent) |
+++ cljs/backup/process.wsf (revision 6) |
@@ -0,0 +1,387 @@ |
+<job id="process"> |
+<!-- |
+This file generates the FAQ index.html |
+--> |
+<SCRIPT> |
+/** |
+ * Formatting - Still messy. |
+ * Needed corrections: |
+ * statements terminated with semicolon. |
+ * use |var| for variables. |
+ * use whitespace. |
+ * 2 spaces for indentation (not one). |
+ */ |
+var CheckUrls=false, |
+ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); |
+ |
+// moomin.utilities can be got from http://www.e-media.co.uk/earl/ |
+// var mu=new ActiveXObject("Moomin.Utilities") |
+ |
+var xml = new ActiveXObject("Microsoft.XMLDOM"); |
+xml.async = false; |
+xml.validateOnParse = false; |
+xml.resolveExternals = false; |
+xml.load("index.xml"); |
+xml.save("indexold.xml"); |
+ |
+var faqNode = xml.selectSingleNode("/FAQ"), |
+ Version = faqNode.attributes.getNamedItem("VERSION").nodeValue, |
+ maintainer = "Garrett Smith", |
+ Updated = faqNode.attributes.getNamedItem("DATE").nodeValue; |
+ |
+var str = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" \n' |
+ + '"http://www.w3.org/TR/html4/strict.dtd">\n<html lang="en">\n' |
+ + '<head>\n' |
+ + '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n' |
+ + '<meta name="DCTERMS.language" scheme="RFC1766" content="en">\n' |
+ + '<meta name="DC.title" content="comp.lang.javascript Frequently Asked Questions">\n' |
+ + '<meta name="DCTERMS.subject" ' |
+ + 'content="Frequently asked questions in the Usenet newsgroup comp.lang.javascript">\n' |
+ + '<meta name="DC.format" content="text/html">\n' |
+ + '<meta name="DC.type" content="Text">\n' |
+ + '<meta name="DC.creator" content="Jim Ley">\n' |
+ + '<meta name="DC.publisher" content="' + maintainer + '">\n' |
+ + '<META name="DC.Publisher.Address" ' |
+ + 'content="dhtmlkitchen@gmail.com">\n' |
+ + '<meta name="DCTERMS.modified" content="' + Updated +'">\n' |
+ + '<meta name="DCTERMS.audience" content="Programmers, web developers">\n' |
+ + '<meta name="DC.description" content="Javascript Frequently Asked Questions">\n' |
+ + '<meta name="DC.identifier" content="http://jibbering.com/faq">\n' |
+ + '<meta name="DC.source" ' |
+ + 'content="http://www.ecma-international.org/publications/standards/Ecma-262.htm">\n' |
+ + '<meta name="DC.source" content="news:comp.lang.javascript">\n' |
+ + '<meta name="DC.source" content="https://developer.mozilla.org/en/JavaScript">\n' |
+ + '<meta name="DC.source" content="http://msdn.microsoft.com/en-us/library/hbxc2t98%28VS.85%29.aspx">\n' |
+ + '<meta name="DC.source" content="http://msdn.microsoft.com/en-us/library/ms533050%28VS.85%29.aspx">\n' |
+ + '<meta name="DC.rights" content="copyright contributors, comp.lang.javascript">\n' |
+ + '<link rel="StyleSheet" href="faq.css" type="text/css" media="screen">\n'; |
+ |
+TitleStr = xml.selectSingleNode("/FAQ/TITLE").firstChild.nodeValue; |
+ |
+str += "<title> "+TitleStr+"</title>\n" |
+ + '</head>\n <body>\n' |
+ + "<h1> "+TitleStr+"</h1>\n" |
+ + "<p>Version "+Version+", Updated "+Updated +", by " + maintainer + "</p>" |
+ + '<div id="nav"><a href="notes/">FAQ Notes</a></div>'; |
+ |
+var contentstr = ""; |
+Contents = xml.selectSingleNode("/FAQ/CONTENTS").selectNodes("CONTENT"); |
+ |
+str += "\n<ul id='faqList'>\n"; |
+ |
+for (var i = 0; i < Contents.length; i++) { |
+ CNode = Contents[i]; |
+ var sectionId = CNode.getAttribute("ID") || "", |
+ title = CNode.getAttribute("TITLE"); |
+ |
+ str += "<li>" + (i+1) + " <a href='#" + sectionId +"'>" + title + "</a>\n"; |
+ |
+ contentstr += "<div id='" + sectionId +"' class='section'>" |
+ + "<h2"+getOldId(CNode)+">" |
+ + (i+1) + " " + title |
+ + "</h2>\n" |
+ + processContentChildren(CNode) |
+ + "</div>"; |
+ |
+ var SubContents = CNode.selectNodes("CONTENT"); |
+ processContentChildren(CNode); |
+ if(SubContents.length > 0) { |
+ str += "\n<ul>\n"; |
+ |
+ // Build a link to a subsection. |
+ // a subsection looks like: |
+ // <h3 id=[FAQ5_7 | getWindowSize]><a name=FAQ5_7></a> ... </h3> |
+ // This allows for items to be moved around in various |
+ // order (index should not matter). |
+ |
+ for (var j = 0; j < SubContents.length; j++) { |
+ var SubCNode = SubContents[j], |
+ subSectionId = SubCNode.getAttribute("ID"), |
+ title = SubCNode.getAttribute("TITLE"), |
+ entryNumber = ""+(i+1)+"."+ (j+1); |
+ |
+ str += "<li>" + entryNumber +" <a href='#"+ subSectionId +"'>" + title + "</a></li>\n"; |
+ |
+ contentstr += "<div id='" + subSectionId + "' class='section'>" |
+ + "<h3" + getOldId(SubCNode) + ">" |
+ + entryNumber + " " + title |
+ + '</h3>' |
+ + processContentChildren(SubCNode ) |
+ + '</div>' |
+ + '\n'; |
+ } |
+ str += "</ul>"; |
+ } |
+ str += "</li>"; |
+} |
+ |
+/** |
+ * If the node contains a "NUMID", |
+ * the content is wrapped in an anchor, e.g. "<a name='" + NUMID. |
+ * Otherwise, returns the content. |
+ */ |
+function getOldId(node) { |
+ var faqSectionIndexString = node.getAttribute("NUMID") || ""; |
+ return (faqSectionIndexString ? |
+ " id='FAQ" + faqSectionIndexString +"'" : ""); |
+} |
+ |
+str += "</ul>" |
+ + contentstr |
+ + "<!--<script src='FAQReader.js' type='text/javascript'><\/script>-->" |
+ + "</body> \n</html> \n"; |
+str = str.replace(/<p><\/p>/gm,"").replace(/<p> <\/p>/gm,""); |
+ |
+// Create the files. |
+var FSO = new ActiveXObject("Scripting.FileSystemObject"); |
+FIL = FSO.CreateTextFile("index"+Version+".html",true); |
+FIL.WriteLine(str); |
+FIL.close(); |
+FIL=FSO.CreateTextFile("index.html",true); |
+FIL.WriteLine(str); |
+FIL.close(); |
+if (CheckUrls) { |
+ xml.save("index.xml"); |
+ xml.save("index"+Version+".xml"); |
+} |
+ |
+function processContentChildren(cNode) { |
+ var allNodes = cNode.selectNodes("*"), |
+ contentstr = "";; |
+ for(var k = 0; k < allNodes.length; k++) { |
+ var node = allNodes[k]; |
+ if(node.tagName == "P") |
+ contentstr += ProcessNode(node); |
+ |
+ // List nodes, for UL, OL, DL. |
+ else if(node.tagName == "LIST") |
+ contentstr += processList(allNodes[k]); |
+ } |
+ return contentstr; |
+} |
+ |
+function ProcessNode(nde) { |
+ var str = " ", p = "", closeP = "", child; |
+ if(nde.tagName == "P") { |
+ str = "<p>\n "; |
+ p = "<p>"; |
+ closeP = "</p>"; |
+ } |
+ for (var i = 0;i < nde.childNodes.length; i++) { |
+ child = nde.childNodes[i]; |
+ switch (child.nodeName) { |
+ case "#comment" : |
+ str += "<!--" + child.data + "-->"; |
+ break; |
+ case "#text" : |
+ // If a text node is empty, do not generate an empty <p> tag. |
+ if(child.nodeValue.replace(/\s+/,'') == "") return " "; |
+ str += child.nodeValue; |
+ break; |
+ case "VER" : |
+ str += Version; |
+ break; |
+ case "UPDATED" : |
+ str += Updated; |
+ break; |
+ case "URL" : |
+ str += makeLink(child); |
+ break; |
+ case "EM" : |
+ var url= child.firstChild.nodeValue; |
+ str+=' <em>'+url+'</em>'; |
+ break; |
+ case "NEWSGROUP" : |
+ var url= child.firstChild.nodeValue; |
+ str+=' <a href="news:'+url+'">'+url+'</a>'; |
+ break; |
+ case "MAILTO" : |
+ var url= child.firstChild.nodeValue; |
+ str+=' <a href="mailto:'+url+'">'+url+'</a>'; |
+ break; |
+ case "MOREINFO" : |
+ str += closeP + ProcessResource(child) + p; |
+ break; |
+ case "UL" : |
+ str+= closeP + " \n<ul> "+ProcessUL(nde.childNodes[i])+"</ul> \n" + p; |
+ break; |
+ case "LI" : |
+ str+="<li> "+ ProcessNode( child ) + "</li>"; |
+ break; |
+ case "CODE" : |
+ str+= closeP + "\n<pre>"+ child.firstChild.nodeValue +"</pre>\n"+p; |
+ break; |
+ case "ICODE" : |
+ str += "<code>"+ child.firstChild.nodeValue+"</code>"; |
+ break; |
+ case "DFN" : |
+ var title = child.attributes.getNamedItem("TITLE"); |
+ title = title && (" title = '" + title.nodeValue +"'") || ""; |
+ str +="\n<dfn" + title + ">" |
+ + child.firstChild.nodeValue + "</dfn>"; |
+ break; |
+ default: |
+ str += child.nodeValue; |
+ break; |
+ } |
+ } |
+ return str+= closeP + " "; |
+} |
+ |
+function makeLink(child) { |
+ var url = child.firstChild.nodeValue, |
+ linkText = child.attributes.getNamedItem("LINKTEXT"), |
+ addstr = checkUrl(url, child); |
+ linkText = linkText && linkText.nodeValue; |
+ return '<a href="'+url+'" '+addstr+'>'+(linkText||url)+'</a>'; |
+} |
+ |
+/** Processing for OL, UL, DL. |
+ * calls processNode. |
+ */ |
+function processList(list) { |
+ var str = "", |
+ header = "", |
+ title = list.getAttribute("TITLE"), |
+ id = list.getAttribute("ID"), |
+ idStr = (id && " id='" + id + "'") || ""; |
+ |
+ if(title) { |
+ header = "\n<h4" + idStr +">" + title + "</h4>\n"; |
+ idStr = ""; // Output id only once. |
+ } |
+ |
+ var type = list.getAttribute("TYPE"); |
+ type = (type || "ul").toLowerCase(); |
+ |
+ str += "\n<" + type + idStr +">"; |
+ |
+ for (var i = 0; i < list.childNodes.length; i++) { |
+ var child = list.childNodes[i], |
+ tagName = child.nodeName; |
+ |
+ // If not a list-type element, |
+ // add it to the header (will appear first). |
+ if(!/(?:LI)|(?:DT)|(?:DD)/.test(tagName)) { |
+ header += ProcessNode(child); |
+ } |
+ else if(tagName !== "#text") { |
+ tagName = tagName.toLowerCase(); |
+ str += "\n <" +tagName +">" + ProcessNode(child) + "</" +tagName +">"; |
+ } |
+ } |
+ return header + str + "</" + type + ">"; |
+} |
+ |
+ function ProcessUL(nde) { |
+ var str="" |
+ for (var i=0;i<nde.childNodes.length;i++) { |
+ |
+ var child = nde.childNodes[i]; |
+ |
+ switch (nde.childNodes[i].nodeName) { |
+ case "#text" : |
+ str+=nde.childNodes[i].nodeValue; |
+ break; |
+ case "VER" : |
+ str+=Version |
+ break; |
+ case "URL" : |
+ str += makeLink(child); |
+ break; |
+ case "NEWSGROUP" : |
+ var url = child.firstChild.nodeValue |
+ str+=' <a href="news:'+url+'">'+url+'</a> \n' |
+ break; |
+ case "MAILTO" : |
+ var url= child.firstChild.nodeValue; |
+ str+=' <a href="mailto:'+url+'">'+url+'</a> \n' |
+ break; |
+ case "UL" : |
+ str+="<ul>\n" + ProcessNode(child) + "\n</ul>\n" |
+ break; |
+ case "LI" : |
+ str+="<li> " + ProcessNode(child) + "</li> \n" |
+ break; |
+ case "CODE" : |
+ str+="</p>\n<pre>"+nde.childNodes[i].firstChild.nodeValue.replace('\r',"<BR> ")+"</pre> \n<p> \n" |
+ break; |
+ case "ICODE" : |
+ str+="<code>"+nde.childNodes[i].firstChild.nodeValue+"</code>\n" |
+ break; |
+ default: |
+ document.write(nde.childNodes[i].nodeName+'<br> \n') |
+ str+=nde.childNodes[i].nodeValue; |
+ break; |
+ } |
+ } |
+ return str += ""; |
+ } |
+ |
+ |
+function ProcessResource(nde) { |
+ var str="<ul class='linkList'>", child; |
+ for (var i = 0; i < nde.childNodes.length; i++) { |
+ child = nde.childNodes[i]; |
+ switch (child.nodeName) { |
+ case "#text" : |
+ if(/[a-zA-Z]/.test(child.nodeValue)) |
+ str += '<li>' + child.nodeValue + '</li>\n'; |
+ break; |
+ case "URL" : |
+ str+='<li>' + makeLink(child) + '</li>\n'; |
+ break; |
+ case "NEWSGROUP" : |
+ var url = child.firstChild.nodeValue; |
+ str += '<li><a href="news:'+url+'">' + url + '</a></li> \n'; |
+ break; |
+ |
+ } |
+ } |
+ return str + "</ul>"; |
+} |
+ |
+ function checkUrl(url,node) { |
+ url=url.split('#')[0] |
+ if (CheckUrls) { |
+ if (url.indexOf('http://')==0) { |
+ xmlhttp.Open("get",url,false) |
+ try { |
+ xmlhttp.Send() |
+ } catch (e) { WScript.Echo(url);return ""; } |
+ stat=xmlhttp.status |
+ node.attributes.getNamedItem("status").nodeValue=stat |
+ if (stat==200) { |
+ source=xmlhttp.responseText |
+ if (url.indexOf('microsoft')!=-1 && source.indexOf('Page Cannot')!=-1) { |
+ //Ugly hack 'cos MSDN don't understand HTTP. |
+ stat=404 |
+ node.attributes.getNamedItem("status").nodeValue=stat |
+ return ' class="nolink" ' |
+ } |
+ contentlength=source.length |
+// oldhash=node.attributes.getNamedItem("hash").nodeValue |
+// hash=mu.MD5(source,"faq") |
+// node.attributes.getNamedItem("hash").nodeValue=hash |
+ classstr="" |
+// if (oldhash!=hash) classstr=' class="updated"' |
+ lm=xmlhttp.getResponseHeader("Last-Modified") |
+ return classstr+' title="'+lm+'" ' |
+ } else { |
+ xmlhttp.Open("get","http://www.google.com/search?q=cache:"+url,false) |
+ xmlhttp.Send() |
+ if (xmlhttp.responseText.indexOf('did not match any documents')==-1) { |
+ return ' class="nolink"> \n<small> \n<a href="http://www.google.com/search?q=cache:'+url+'>(Googles cached copy)</a> \n<small' |
+ } |
+ return ' class="nolink" ' |
+ } |
+ } else { |
+ return "" |
+ } |
+ } else { |
+ return "" |
+ } |
+ |
+ } |
+</SCRIPT> |
+</job> |