<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ajaxian &#187; Tip</title>
	<atom:link href="http://ajaxian.com/by/topic/tip/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Fri, 19 Mar 2010 12:40:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gmail Mobile team talks Latency and Code Loading</title>
		<link>http://ajaxian.com/archives/gmail-mobile-latency</link>
		<comments>http://ajaxian.com/archives/gmail-mobile-latency#comments</comments>
		<pubDate>Tue, 22 Sep 2009 11:09:43 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7404</guid>
		<description><![CDATA[Bikin Chiu of the Gmail Mobile team picks up the HTML5 series with a piece on reducing startup latency.
It starts off by talking about lazily loading code via the old favorites of adding a &#60;script&#62; to the DOM, or XHR+eval, but then it gets beyond the typical and discusses the nuance of mobile + offline [...]]]></description>
			<content:encoded><![CDATA[<p>Bikin Chiu of the Gmail Mobile team picks up the HTML5 series with a piece on <a href="http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-series-reducing.html">reducing startup latency</a>.</p>
<p>It starts off by talking about lazily loading code via the old favorites of adding a &lt;script&gt; to the DOM, or XHR+eval, but then it gets beyond the typical and discusses the nuance of mobile + offline caching. The hack that is used, is another oldie.... which is to hide the script and eval it later:</p>
<blockquote><p>
For an HTML 5 application that takes advantage of the application cache to reduce startup latency and to serve the application offline, there are a few caveats one should be aware of. Mobile networks have decent bandwidth, but poor round trip latency, so listing each module as a separate resource in the manifest incurs quite a bit of extra startup latency when the application cache is empty. Also, if one of the module resources fails to be downloaded by the application cache (e.g. disconnected from network), additional error handling code needs to be written to handle such a case. Finally, applications today have no control when the application cache decides to download the resources in the manifest (such a feature is not defined in the current specification of the draft standard). Typically, resources are downloaded once the main page is loaded, but that's not an ideal time since that's when the application requests user data.</p>
<p>To work-around these caveats, we found a trick that allows you to bundle all of your modules into a single resource without having to parse any of the JavaScript. Of course, with this strategy, there is greater latency with the initial download of the single resource (since it has all your JavaScript modules), but once the resource is stored in the browser's application cache, this issue becomes much less of a factor.</p>
<p>To combine all modules into a single resource, we wrote each module into a separate script tag and hid the code inside a comment block (/* */). When the resource first loads, none of the code is parsed since it is commented out. To load a module, find the DOM element for the corresponding script tag, strip out the comment block, and eval() the code. If the web app supports XHTML, this trick is even more elegant as the modules can be hidden inside a CDATA tag instead of a script tag. An added bonus is the ability to lazy load your modules synchronously since there's no longer a need to fetch the modules asynchronously over the network.</p>
<p>On an iPhone 2.2 device, 200k of JavaScript held within a block comment adds 240ms during page load, whereas 200k of JavaScript that is parsed during page load added 2600 ms. That's more than a 10x reduction in startup latency by eliminating 200k of unneeded JavaScript during page load! Take a look at the code sample below to see how this is done. </p>
<div class="igBar"><a href="javascript:showCodeTxt('html-2');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-2">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"lazy"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">// Make sure you strip out (or replace) comment blocks in your JavaScript first.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">/*</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">JavaScript of lazy module</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">*/</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">&lt;script&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; function lazyLoad() {</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; var lazyElement = document.getElementById('lazy');</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; var lazyElementBody = lazyElement.innerHTML;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; var jsCode = stripOutCommentBlock(lazyElementBody);</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; eval(jsCode);</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; }</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>In the future, we hope that the HTML5 standard will allow more control over when the application cache should download resources in the manifest, since using comments to pass along code is not elegant but worked nicely for us.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/gmail-mobile-latency/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>FireCrystal: Observe and roll back interactions</title>
		<link>http://ajaxian.com/archives/firecrystal-observe-and-roll-back-interactions</link>
		<comments>http://ajaxian.com/archives/firecrystal-observe-and-roll-back-interactions#comments</comments>
		<pubDate>Wed, 02 Sep 2009 11:52:18 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7312</guid>
		<description><![CDATA[
FireCrystal is a Firefox extension that helps designers and programmers alike figure out how interactive behaviors on the web work. FireCrystal allows users to record and rewind their interactions with web pages while showing the relevant code.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://stephenoney.com/images/firecrystal_nyt.png"></p>
<p></a><a href="http://stephenoney.com/firecrystal.php">FireCrystal</a> is a Firefox extension that helps designers and programmers alike figure out how interactive behaviors on the web work. FireCrystal allows users to record and rewind their interactions with web pages while showing the relevant code.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/firecrystal-observe-and-roll-back-interactions/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Text rotation for all</title>
		<link>http://ajaxian.com/archives/text-rotation-for-all</link>
		<comments>http://ajaxian.com/archives/text-rotation-for-all#comments</comments>
		<pubDate>Wed, 29 Jul 2009 15:20:59 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7154</guid>
		<description><![CDATA[Jonathan Snook has posted a nice nugget on text rotation with CSS that takes a nice bit of markup like this:
PLAIN TEXT
HTML:




&#160;


&#60;div class="example-date"&#62;


&#160; &#60;span class="day"&#62;31&#60;/span&#62; 


&#160; &#60;span class="month"&#62;July&#60;/span&#62; 


&#160; &#60;span class="year"&#62;2009&#60;/span&#62;


&#60;/div&#62;


&#160;





and converts it to:

all via the CSS:
PLAIN TEXT
CSS:




&#160;


-webkit-transform: rotate&#40;-90deg&#41;; 


-moz-transform: rotate&#40;-90deg&#41;;


filter: progid:DXImageTransform.Microsoft.BasicImage&#40;rotation=3&#41;;


&#160;





Yup, even IE.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/snookca">Jonathan Snook</a> has posted a nice nugget on <a href="http://snook.ca/archives/html_and_css/css-text-rotation">text rotation with CSS</a> that takes a nice bit of markup like this:</p>
<div class="igBar"><a href="javascript:showCodeTxt('html-5');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-5">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"example-date"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"day"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>31<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"month"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>July<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/span.html"><span style="color: #000000; font-weight: bold;">&lt;span</span></a> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"year"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span>2009<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>and converts it to:</p>
<p><img src="http://snook.ca/technical/text-rotation/text-rotation.png"/></p>
<p>all via the CSS:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-6');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-6">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">-webkit-transform: rotate<span style="color:#006600; font-weight:bold;">&#40;</span>-90deg<span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">-moz-transform: rotate<span style="color:#006600; font-weight:bold;">&#40;</span>-90deg<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">filter: progid:DXImageTransform.Microsoft.BasicImage<span style="color:#006600; font-weight:bold;">&#40;</span>rotation=<span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Yup, even IE.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/text-rotation-for-all/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>More than you ever want to see about encoding</title>
		<link>http://ajaxian.com/archives/encoding</link>
		<comments>http://ajaxian.com/archives/encoding#comments</comments>
		<pubDate>Thu, 02 Jul 2009 10:03:19 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7043</guid>
		<description><![CDATA[Paul Baukaus linked to jsescape, a little form that shows escaping and unescaping across a number of encodings.

Andrea Giammarchi had his own post on encodings in a different way.... as he talked about
en-code which you can check out in action here on the page that lets you do simple encodings, especially for source code, in [...]]]></description>
			<content:encoded><![CDATA[<p>Paul Baukaus linked to <a href="http://0xcc.net/jsescape/">jsescape</a>, a little form that shows escaping and unescaping across a number of encodings.</p>
<p><img src="http://ajaxian.com/wp-content/uploads/encodings.png" alt="" title="encodings" width="488" height="802" class="alignnone size-full wp-image-7044" /></p>
<p>Andrea Giammarchi had his own post on encodings in a different way.... as he talked about<br />
<a href="http://webreflection.blogspot.com/2009/05/en-code-quickest-way-to-encode-your.html">en-code</a> which you can <a href="http://www.3site.eu/encode/">check out in action here</a> on the page that lets you do simple encodings, especially for source code, in short order.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/encoding/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>CSS Browser Hacks</title>
		<link>http://ajaxian.com/archives/css-browser-hacks</link>
		<comments>http://ajaxian.com/archives/css-browser-hacks#comments</comments>
		<pubDate>Fri, 24 Apr 2009 15:35:21 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=6646</guid>
		<description><![CDATA[Paul Irish tries not to use CSS browser hacks anymore and instead "uses IE's conditional comments to apply classes to the body tag, but he put up a concise list of browser specific hacks he has used:
PLAIN TEXT
CSS:




&#160;


/***** Selector Hacks ******/


&#160;


/* IE 6 and below */


* html #uno&#160; &#123; color: red &#125;


&#160;


/* IE 7 and [...]]]></description>
			<content:encoded><![CDATA[<p>Paul Irish tries not to use CSS browser hacks anymore and instead "<a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">uses IE's conditional comments to apply classes to the body tag</a>, but he put up a concise list of <a href="http://paulirish.com/2009/browser-specific-css-hacks/">browser specific hacks he has used</a>:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-8');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-8">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/***** Selector Hacks ******/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* IE 6 and below */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">* html <span style="color: #cc00cc;">#uno&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* IE 7 and below */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">*:first-child+html <span style="color: #cc00cc;">#dos <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* IE 7 and modern browsers */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">html&gt;body <span style="color: #cc00cc;">#tres <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* Modern browsers (not IE 7) */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">html&gt;<span style="color: #808080; font-style: italic;">/**/</span>body <span style="color: #cc00cc;">#cuatro <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* Opera 9.27 and below */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">html<span style="color: #3333ff;">:first-child </span><span style="color: #cc00cc;">#cinco <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* Safari */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">html<span style="color:#006600; font-weight:bold;">&#91;</span>xmlns*=<span style="color: #ff0000;">""</span><span style="color:#006600; font-weight:bold;">&#93;</span> body<span style="color: #3333ff;">:last-child </span><span style="color: #cc00cc;">#seis <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/*safari 3+, chrome 1+, opera9+, ff 3.5+ */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">body:nth-of-type<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #cc00cc;">#siete <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* safari 3+, chrome 1+, opera9+, ff 3.5+ */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">body<span style="color: #3333ff;">:first-of-type </span><span style="color: #cc00cc;">#ocho <span style="color:#006600; font-weight:bold;">&#123;</span></span>&nbsp; <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #993333;">red</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* saf3, chrome1+ */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">@media screen and (-webkit-min-device-pixel-ratio:0) {</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color: #cc00cc;">#diez&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">background</span>: #FFDECE; <span style="color: #000000; font-weight: bold;">border</span>: 2px <span style="color: #993333;">solid</span> #ff0000&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/***** Attribute Hacks ******/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* ie6 and below */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc00cc;">#once <span style="color:#006600; font-weight:bold;">&#123;</span></span> _color<span style="color: #3333ff;">:<span style="color: #000000; font-weight: bold;">blue</span> </span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* ie7 and below */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc00cc;">#doce <span style="color:#006600; font-weight:bold;">&#123;</span></span> *<span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #000000; font-weight: bold;">blue</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #808080; font-style: italic;">/* or #color:blue */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">/* 'Modern Browsers' includes IE8, whether you agree or not.. :) */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>He has included a <a href="http://paulirish.com/work/csshacks.html">test page</a> and you can view the <a href="http://browsershots.org/http://paulirish.com/work/csshacks.html">different browsers via browsershots</a>.</p>
<p>Finally, he links to another concise list... of <a href="http://www.thespanner.co.uk/2009/01/29/detecting-browsers-javascript-hacks/">JavaScript sniffs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/css-browser-hacks/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How many ways can you iterate over an array in JavaScript?</title>
		<link>http://ajaxian.com/archives/how-many-ways-can-you-iterate-over-an-array-in-javascript</link>
		<comments>http://ajaxian.com/archives/how-many-ways-can-you-iterate-over-an-array-in-javascript#comments</comments>
		<pubDate>Thu, 23 Apr 2009 09:29:51 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=6643</guid>
		<description><![CDATA[Myk is one of the nicest chaps that I have had the pleasure to sit closely to in Mozilla building "S".
He has a nice little tip on the many syntaxes that you can use to iterate over arrays in various JavaScript implementations and standards. Some folks had some interesting points on the various approaches:

for each [...]]]></description>
			<content:encoded><![CDATA[<p>Myk is one of the nicest chaps that I have had the pleasure to sit closely to in Mozilla building "S".</p>
<p>He has a nice little tip on <a href="http://www.melez.com/mykzilla/2009/04/syntaxes-for-iterating-arrays-in.html">the many syntaxes that you can use to iterate over arrays in various JavaScript implementations and standards</a>. Some folks had some interesting points on the various approaches:</p>
<blockquote>
<p><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/for_each...in">for each in</a>:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-15');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-15">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">for</span> each <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #000066; font-weight: bold;">in</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span>, <span style="color:#800000;">2</span>, <span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>The MDC docs for "for each" say not to iterate arrays that way, too, so I never use it on them. The usual (would need to guard with <code>hasOwnProperty()</code> issue).</p>
<p><a href="https://developer.mozilla.org/en/New_in_JavaScript_1.6">JavaScript 1.6</a> added the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach">Array.forEach method</a>:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-16');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-16">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span>, <span style="color:#800000;">2</span>, <span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color: #006600;">forEach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p><a href="https://developer.mozilla.org/En/New_in_JavaScript_1.7">JavaScript 1.7</a> added <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Arrays#Array_comprehensions">array comprehensions</a> for array initialization:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-17');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-17">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> squares = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #000066; font-weight: bold;">item</span> * <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #000066; font-weight: bold;">for</span> each <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span> <span style="color: #000066; font-weight: bold;">in</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span>, <span style="color:#800000;">2</span>, <span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>I just realized I can (ab)use comprehensions to iterate arrays with Perl-like syntax by throwing away the result:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-18');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-18">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #000066; font-weight: bold;">for</span> each <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span> <span style="color: #000066; font-weight: bold;">in</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span>, <span style="color:#800000;">2</span>, <span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>I can iterate object properties the same way:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-19');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-19">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> obj = <span style="color:#006600; font-weight:bold;">&#123;</span> foo: <span style="color:#800000;">1</span>, bar: <span style="color:#800000;">2</span>, baz: <span style="color:#800000;">3</span> <span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066;">name</span> + <span style="color: #3366CC;">"="</span> + obj<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #000066;">name</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066;">name</span> <span style="color: #000066; font-weight: bold;">in</span> obj<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Edward Lee points out how to use Iterators:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-20');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-20">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #000066;">alert</span><span style="color:#006600; font-weight:bold;">&#40;</span>key + <span style="color: #3366CC;">"="</span> + val<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>key, val<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color: #000066; font-weight: bold;">in</span> Iterator<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>a:<span style="color:#800000;">1</span>,b:<span style="color:#800000;">2</span>,c:<span style="color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/how-many-ways-can-you-iterate-over-an-array-in-javascript/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Detecting event support in browsers</title>
		<link>http://ajaxian.com/archives/detecting-event-support-in-browsers</link>
		<comments>http://ajaxian.com/archives/detecting-event-support-in-browsers#comments</comments>
		<pubDate>Fri, 03 Apr 2009 12:19:57 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=6487</guid>
		<description><![CDATA[Kangax has a really nice article on testing for event support in browsers in which he delves into the quirks and work-arounds needed to get 'er done, coming up with a nice generic solution:
PLAIN TEXT
JAVASCRIPT:




&#160;


&#160; var isEventSupported = &#40;function&#40;&#41;&#123;


&#160; &#160; var TAGNAMES = &#123;


&#160; &#160; &#160; 'select':'input','change':'input',


&#160; &#160; &#160; 'submit':'form','reset':'form',


&#160; &#160; &#160; 'error':'img','load':'img','abort':'img'


&#160; &#160; &#125;


&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Kangax <a href="http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/">has a really nice article on testing for event support in browsers</a> in which he delves into the quirks and work-arounds needed to get 'er done, coming up with a nice generic solution:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-22');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-22">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> isEventSupported = <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> TAGNAMES = <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'select'</span>:<span style="color: #3366CC;">'input'</span>,<span style="color: #3366CC;">'change'</span>:<span style="color: #3366CC;">'input'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'submit'</span>:<span style="color: #3366CC;">'form'</span>,<span style="color: #3366CC;">'reset'</span>:<span style="color: #3366CC;">'form'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'error'</span>:<span style="color: #3366CC;">'img'</span>,<span style="color: #3366CC;">'load'</span>:<span style="color: #3366CC;">'img'</span>,<span style="color: #3366CC;">'abort'</span>:<span style="color: #3366CC;">'img'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span> isEventSupported<span style="color:#006600; font-weight:bold;">&#40;</span>eventName<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> el = document.<span style="color: #006600;">createElement</span><span style="color:#006600; font-weight:bold;">&#40;</span>TAGNAMES<span style="color:#006600; font-weight:bold;">&#91;</span>eventName<span style="color:#006600; font-weight:bold;">&#93;</span> || <span style="color: #3366CC;">'div'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; eventName = <span style="color: #3366CC;">'on'</span> + eventName;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> isSupported = <span style="color:#006600; font-weight:bold;">&#40;</span>eventName <span style="color: #000066; font-weight: bold;">in</span> el<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!isSupported<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; el.<span style="color: #006600;">setAttribute</span><span style="color:#006600; font-weight:bold;">&#40;</span>eventName, <span style="color: #3366CC;">'return;'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; isSupported = <span style="color: #000066; font-weight: bold;">typeof</span> el<span style="color:#006600; font-weight:bold;">&#91;</span>eventName<span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color: #3366CC;">'function'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; el = <span style="color: #003366; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> isSupported;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> isEventSupported;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Along with this, he put up a <a href="http://yura.thinkweb2.com/isEventSupported/">simple test case</a> that you can point at.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/detecting-event-support-in-browsers/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Calculate your content to markup ratio</title>
		<link>http://ajaxian.com/archives/calculate-your-content-to-markup-ratio</link>
		<comments>http://ajaxian.com/archives/calculate-your-content-to-markup-ratio#comments</comments>
		<pubDate>Fri, 06 Mar 2009 07:58:28 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=6193</guid>
		<description><![CDATA[Stoyan Stefanov has created a fun little bookmarklet that calculates the content to markup ratio of a webpage:

When you care about performance, or SEO (or just doing a good job as web dev) an interesting data point is the ratio of page content vs. the markup used to present this content. Or... how much crap [...]]]></description>
			<content:encoded><![CDATA[<p>Stoyan Stefanov has created a fun little bookmarklet that <a href="http://www.phpied.com/content-to-markup-ratio-bookmarklet/">calculates the content to markup ratio</a> of a webpage:</p>
<blockquote><p>
When you care about performance, or SEO (or just doing a good job as web dev) an interesting data point is the ratio of page content vs. the markup used to present this content. Or... how much crap we put in HTML in order to present what the users want to see - the content.</p>
<p>So I played tonight with a bookmarklet to provide this piece of stats.</p>
<p>The bookmarklet code is served from <a href="http://phpied.com/files/bookmarklets/content2markup.js">here</a>. The code is also on <a href="http://github.com/stoyan/etc/blob/master/content2markup/content2markup.js">github</a>.
</p></blockquote>
<p>And some fun results:</p>
<p>Here are some random results of running the bookmarklet on different sites.</p>
<p>http://www.cnn.com:<br />
Total size: 92004 bytes<br />
Content size: 11475 bytes<br />
Content-to-markup ratio: 0.12<br />
Fair ratio * : 0.16</p>
<p>http://www.sitepoint.com</p>
<p>Total size: 65989 bytes<br />
Content size: 16199 bytes<br />
Content-to-markup ratio: 0.25<br />
Fair ratio * : 0.60</p>
<p>Article on http://en.wikipedia.org:<br />
Total size: 21648 bytes<br />
Content size: 3315 bytes<br />
Content-to-markup ratio: 0.15<br />
Fair ratio * : 0.35</p>
<p>http://www.phpied.com<br />
Total size: 31899 bytes<br />
Content size: 7933 bytes<br />
Content-to-markup ratio: 0.25<br />
Fair ratio * : 0.48</p>
<p>http://www.google.com SERP<br />
Total size: 29963 bytes<br />
Content size: 3351 bytes<br />
Content-to-markup ratio: 0.11<br />
Fair ratio * : 0.14</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/calculate-your-content-to-markup-ratio/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Watching Prototype events and a nice little tip</title>
		<link>http://ajaxian.com/archives/watching-prototype-events-and-a-nice-little-tip</link>
		<comments>http://ajaxian.com/archives/watching-prototype-events-and-a-nice-little-tip#comments</comments>
		<pubDate>Mon, 23 Feb 2009 11:56:09 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=6063</guid>
		<description><![CDATA[Kangax shows a nice use of Prototype as he writes a tip to let you see your Prototype based events as they run in your application. A nice little view.
He also realized that the core piece of the bookmarklet is actually a nice view of the power of Prototype as a library:
PLAIN TEXT
JAVASCRIPT:




&#160;


$H&#40;Event.cache&#41;.inject&#40;0, function&#40;m, p&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Kangax shows a nice use of Prototype as he <a href="http://thinkweb2.com/projects/prototype/event-delegation-will-save-the-world/">writes a tip to let you see your Prototype based events</a> as they run in your application. A nice little view.</p>
<p>He also realized that the core piece of the <a href="javascript:alert($H(Event.cache).inject(0,function(m,p){m+=$H(p.value).values().flatten().size();return%20m}))">bookmarklet</a> is actually a nice view of the power of Prototype as a library:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-24');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-24">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">$H<span style="color:#006600; font-weight:bold;">&#40;</span>Event.<span style="color: #006600;">cache</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">0</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>m, p<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; m += $H<span style="color:#006600; font-weight:bold;">&#40;</span>p.<span style="color: #006600;">value</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">values</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">flatten</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">size</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">return</span> m;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/watching-prototype-events-and-a-nice-little-tip/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HTML5 Canvas Cheat Sheet</title>
		<link>http://ajaxian.com/archives/html5-canvas-cheat-sheet</link>
		<comments>http://ajaxian.com/archives/html5-canvas-cheat-sheet#comments</comments>
		<pubDate>Mon, 23 Feb 2009 05:56:37 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=6065</guid>
		<description><![CDATA[
Jacob is back, and this time he has a cheat sheet with him. It is nice to see the Canvas API fitting on one sheet here, and I really like the images showing how things look like and work.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html"><img src="http://ajaxian.com/wp-content/uploads/canvascheatsheet.png" alt="" title="canvas cheat sheet" width="472" height="698" class="alignnone size-full wp-image-6066" /></a></p>
<p>Jacob is back, and this time he has <a href="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html">a cheat sheet with him</a>. It is nice to see the Canvas API fitting on one sheet here, and I really like the images showing how things look like and work.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/html5-canvas-cheat-sheet/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE=&#8217;\v&#8217;==&#8217;v&#8217;</title>
		<link>http://ajaxian.com/archives/ievv</link>
		<comments>http://ajaxian.com/archives/ievv#comments</comments>
		<pubDate>Thu, 29 Jan 2009 06:02:52 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5826</guid>
		<description><![CDATA[PLAIN TEXT
JAVASCRIPT:




&#160;


IE='\v'=='v'


&#160;





That is the current winner in the shortest way to test for IE (including 8). The other notable was:
PLAIN TEXT
JAVASCRIPT:




&#160;


IE=top.execScript?1:0


&#160;





Huh :)
Gareth Heyes (the chap who did the v trick) has posted on this himself and comes up with One Line To Rule Them All:
PLAIN TEXT
JAVASCRIPT:




&#160;


B=&#40;function x&#40;&#41;&#123;&#125;&#41;&#91;-5&#93;=='x'?'FF3':&#40;function x&#40;&#41;&#123;&#125;&#41;&#91;-6&#93;=='x'?'FF2':/a/&#91;-1&#93;=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test&#40;/a/.toString&#41;?'Chr':/^function \&#40;/.test&#40;&#91;&#93;.sort&#41;?'Op':'Unknown'


&#160;





]]></description>
			<content:encoded><![CDATA[<div class="igBar"><a href="javascript:showCodeTxt('javascript-28');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-28">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">IE=<span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\v</span>'</span>==<span style="color: #3366CC;">'v'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>That is the current winner in the <a href="http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html">shortest way to test for IE</a> (including 8). The other notable was:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-29');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-29">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">IE=top.<span style="color: #006600;">execScript</span>?<span style="color:#800000;">1</span>:<span style="color:#800000;">0</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Huh :)</p>
<p>Gareth Heyes (the chap who did the v trick) has <a href="http://www.thespanner.co.uk/2009/01/29/detecting-browsers-javascript-hacks/">posted on this himself</a> and comes up with One Line To Rule Them All:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-30');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-30">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">B=<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> x<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>-<span style="color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color: #3366CC;">'x'</span>?<span style="color: #3366CC;">'FF3'</span>:<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> x<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>-<span style="color:#800000;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color: #3366CC;">'x'</span>?<span style="color: #3366CC;">'FF2'</span>:<span style="color: #0066FF;">/a/</span><span style="color:#006600; font-weight:bold;">&#91;</span>-<span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color: #3366CC;">'a'</span>?<span style="color: #3366CC;">'FF'</span>:<span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\v</span>'</span>==<span style="color: #3366CC;">'v'</span>?<span style="color: #3366CC;">'IE'</span>:<span style="color: #0066FF;">/a/</span>.__proto__==<span style="color: #3366CC;">'//'</span>?<span style="color: #3366CC;">'Saf'</span>:<span style="color: #0066FF;">/s/.<span style="color: #006600;">test</span><span style="color:#006600; font-weight:bold;">&#40;</span>/a/</span>.<span style="color: #006600;">toString</span><span style="color:#006600; font-weight:bold;">&#41;</span>?<span style="color: #3366CC;">'Chr'</span>:<span style="color: #0066FF;">/^<span style="color: #003366; font-weight: bold;">function</span> \<span style="color:#006600; font-weight:bold;">&#40;</span>/</span>.<span style="color: #006600;">test</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color: #006600;">sort</span><span style="color:#006600; font-weight:bold;">&#41;</span>?<span style="color: #3366CC;">'Op'</span>:<span style="color: #3366CC;">'Unknown'</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/ievv/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Browser Detection with XSLT</title>
		<link>http://ajaxian.com/archives/browser-detection-with-xslt</link>
		<comments>http://ajaxian.com/archives/browser-detection-with-xslt#comments</comments>
		<pubDate>Tue, 27 Jan 2009 10:50:21 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[xsl]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5797</guid>
		<description><![CDATA[
This is a fun little hack by Manfred Staudinger.
Thanks to select="system-property('xsl:vendor')", he has a style sheet that allows you to show items depending on the browser:

To include a link or a style element for one of the above choices you use the dr:select attribute and specify one or more tokens as a comma separated list. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ajaxian.com/wp-content/uploads/xslbrowsercheck.png" alt="" title="xslbrowsercheck" width="500" height="310" class="alignnone size-full wp-image-5798" /></p>
<p>This is a fun little hack by Manfred Staudinger.</p>
<p>Thanks to <code>select="system-property('xsl:vendor')"</code>, he has a <a href="http://documenta.rudolphina.org/c-cond-html.xsl">style sheet</a> that allows you to <a href="http://documenta.rudolphina.org/cond-css-demo.xml">show items depending on the browser</a>:</p>
<blockquote><p>
To include a link or a style element for one of the above choices you use the dr:select attribute and specify one or more tokens as a comma separated list. For example dr:select="Firefox, Safari 3" will cause the link or style element to be included for any Firefox and for Safari 3. If you specify more than one token, each of which constitutes a positive selection, you may use any combination of tokens from the non-IE browsers plus the token "IE".</p>
<p>To select a specific IE only one token in the dr:select attribute is allowed, because it is directly used in constructing a Conditional Comment (CC). These are constructed on the fly only if the current browser is actually an IE. Any valid CC expression is allowed, so you can specify for example dr:select="lte IE 7" (positive selection) or dr:select="!IE 6" (negative selection). To clarify, a positive CC selection will allow only the IE's specified to read the CSS, and a negative CC will exclude them from seeing it. The best, you don't need anymore to include Microsoft proprietary CC's for selecting CSS in your HTML!</p>
<p>Link and style elements without a dr:select attribute are considered common stylesheets which every browser will see. They will remain unchanged, as any other HTML element. Only the dr:select attributes will be nullified.
</p></blockquote>
<p>You could do this when JavaScript isn't enabled for example.... although I am not sure how practical it actually is :)</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/browser-detection-with-xslt/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Web Resources He Uses</title>
		<link>http://ajaxian.com/archives/web-resources-he-uses</link>
		<comments>http://ajaxian.com/archives/web-resources-he-uses#comments</comments>
		<pubDate>Mon, 19 Jan 2009 10:27:39 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5713</guid>
		<description><![CDATA[
"Ethan" has a really nicely packaged set of web resources that he uses.
From JavaScript core libraries, to widgets, to tools, to CSS frameworks, to CSS techniques, to browser compatibility, to typography, to extensions, and much much more. Nicely done.
]]></description>
			<content:encoded><![CDATA[<p><a href="http://elementiks.com/web_resources.php"><img src="http://ajaxian.com/wp-content/uploads/webresources.png" alt="" title="web resources" width="500" height="325" class="alignnone size-full wp-image-5714" /></a></p>
<p>"Ethan" has a really nicely packaged set of <a href="http://elementiks.com/web_resources.php">web resources</a> that he uses.</p>
<p>From JavaScript core libraries, to widgets, to tools, to CSS frameworks, to CSS techniques, to browser compatibility, to typography, to extensions, and much much more. Nicely done.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/web-resources-he-uses/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Forcing a UI redraw from JavaScript</title>
		<link>http://ajaxian.com/archives/forcing-a-ui-redraw-from-javascript</link>
		<comments>http://ajaxian.com/archives/forcing-a-ui-redraw-from-javascript#comments</comments>
		<pubDate>Mon, 12 Jan 2009 18:45:33 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5640</guid>
		<description><![CDATA[Thomas Fuchs has run into those annoying times when a redraw is required to irk the browser into a correct layout, and his weapon of choice is:
PLAIN TEXT
JAVASCRIPT:




&#160;


Element.addMethods&#40;&#123;


&#160; redraw: function&#40;element&#41;&#123;


&#160; &#160; element = $&#40;element&#41;;


&#160; &#160; var n = document.createTextNode&#40;' '&#41;;


&#160; &#160; element.appendChild&#40;n&#41;;


&#160; &#160; &#40;function&#40;&#41;&#123;n.parentNode.removeChild&#40;n&#41;&#125;&#41;.defer&#40;&#41;;


&#160; &#160; return element;


&#160; &#125;


&#125;&#41;;


&#160;





This is an update to the Script.aculo.us forceRerendering [...]]]></description>
			<content:encoded><![CDATA[<p>Thomas Fuchs has run into those annoying times when a redraw is required to irk the browser into a correct layout, and his weapon of choice is:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-32');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-32">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">Element.<span style="color: #006600;">addMethods</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; redraw: <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>element<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; element = $<span style="color:#006600; font-weight:bold;">&#40;</span>element<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> n = document.<span style="color: #006600;">createTextNode</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; element.<span style="color: #006600;">appendChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span>n.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">removeChild</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">defer</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> element;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>This is an update to the Script.aculo.us <code>forceRerendering</code> so it will probably be in Scripty 2? :)</p>
<p>Sebastian of Qooxdoo had a similar technique:</p>
<blockquote><p>
You may also use some kind of addClass/removeClass combo. That would result into the same effect but without creating unused DOM elements. We use this method in qooxdoo and it works well.
</p></blockquote>
<p>Do you run into these issues?</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/forcing-a-ui-redraw-from-javascript/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Guid0: JavaScript GUIDs</title>
		<link>http://ajaxian.com/archives/guid0-javascript-guids</link>
		<comments>http://ajaxian.com/archives/guid0-javascript-guids#comments</comments>
		<pubDate>Fri, 14 Nov 2008 11:47:33 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=5061</guid>
		<description><![CDATA[Our own Michael Mahemoff is at it again, creating a simple little GUID generator called Guid0:

Guid0 is a GUID library for Javascript. Okay, it doesn't yet do official, bona fide, 128-bit, GUIDs yet, mainly for API design reasons. But this is a library you might find useful if you want to generate a unique ID [...]]]></description>
			<content:encoded><![CDATA[<p>Our own Michael Mahemoff is at it again, creating a simple little <a href="http://softwareas.com/guid0-a-javascript-guid-generator">GUID generator called Guid0</a>:</p>
<blockquote><p>
Guid0 is a GUID library for Javascript. Okay, it doesn't yet do official, bona fide, 128-bit, GUIDs yet, mainly for API design reasons. But this is a library you might find useful if you want to generate a unique ID in your Ajax app.</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-34');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-34">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// simple</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">guid = <span style="color: #003366; font-weight: bold;">new</span> Guid<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> newguid = guid.<span style="color: #006600;">generate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// options</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">guid = <span style="color: #003366; font-weight: bold;">new</span> Guid<span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; chars: Guid.<span style="color: #006600;">constants</span>.<span style="color: #006600;">base85</span>,&nbsp; <span style="color: #009900; font-style: italic;">// or you could say &quot;abc&quot; if you only wanted those chars to appear</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; epoch: <span style="color: #3366CC;">"June 1, 2003"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; counterSequenceLength: <span style="color:#800000;">2</span>, <span style="color: #009900; font-style: italic;">// a counter field appended to the end</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; randomSequenceLength: <span style="color:#800000;">2</span> <span style="color: #009900; font-style: italic;">// a random field appended to the end</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>He is working on 128-bit support.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/guid0-javascript-guids/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Finding those trailing commas</title>
		<link>http://ajaxian.com/archives/finding-those-trailing-commas</link>
		<comments>http://ajaxian.com/archives/finding-those-trailing-commas#comments</comments>
		<pubDate>Wed, 01 Oct 2008 10:37:59 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Tip]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=4649</guid>
		<description><![CDATA[Dan Fabulich got bitten by the "trailing comma" issue one too many times, so he created a script to solve his problem:

“How many thousands of developer hours have been lost to random IE bugs like this?” I asked myself. I decided that there had to be a good way to detect this problem in an [...]]]></description>
			<content:encoded><![CDATA[<p>Dan Fabulich got bitten by the "trailing comma" issue one too many times, so he created a script to solve his problem:</p>
<blockquote><p>
“How many thousands of developer hours have been lost to random IE bugs like this?” I asked myself. I decided that there had to be a good way to detect this problem in an automated way, without firing up a copy of IE and running a full test suite.</p>
<p>It turns out that these and other syntax errors can be detected automatically from the Windows command line, using the Windows Scripting Host (WSH).  On Windows XP and higher, the command-line tool “cscript.exe” can be used to run JavaScript (ahem, JScript) headlessly (outside of any browser).</p>
<p>Just create a file called “wsh-parser.js” like this:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-36');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-36">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> fso = <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color: #3366CC;">"Scripting.FileSystemObject"</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> parse<span style="color:#006600; font-weight:bold;">&#40;</span>fname<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> file = fso.<span style="color: #006600;">OpenTextFile</span><span style="color:#006600; font-weight:bold;">&#40;</span> fname, <span style="color:#800000;">1</span> <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ret = file.<span style="color: #006600;">ReadAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; file.<span style="color: #006600;">Close</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">try</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">eval</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"(function(){<span style="color: #000099; font-weight: bold;">\n</span>"</span>+ret+<span style="color: #3366CC;">"<span style="color: #000099; font-weight: bold;">\n</span>});"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; WScript.<span style="color: #006600;">Echo</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"Syntax error parsing "</span> + fname<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; WScript.<span style="color: #006600;">Echo</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"&nbsp; "</span> + e.<span style="color: #006600;">message</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> findJavaScript<span style="color:#006600; font-weight:bold;">&#40;</span>folder<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> fc = <span style="color: #003366; font-weight: bold;">new</span> Enumerator<span style="color:#006600; font-weight:bold;">&#40;</span>folder.<span style="color: #006600;">files</span><span style="color:#006600; font-weight:bold;">&#41;</span>; !fc.<span style="color: #006600;">atEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; fc.<span style="color: #006600;">moveNext</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> file=fc.<span style="color: #006600;">item</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #0066FF;">/.<span style="color: #006600;">js</span>$/</span>.<span style="color: #006600;">test</span><span style="color:#006600; font-weight:bold;">&#40;</span>file.<span style="color: #006600;">Name</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parse<span style="color:#006600; font-weight:bold;">&#40;</span>file<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> fc = <span style="color: #003366; font-weight: bold;">new</span> Enumerator<span style="color:#006600; font-weight:bold;">&#40;</span>folder.<span style="color: #006600;">subfolders</span><span style="color:#006600; font-weight:bold;">&#41;</span>; !fc.<span style="color: #006600;">atEnd</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; fc.<span style="color: #006600;">moveNext</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> subfolder = fc.<span style="color: #006600;">item</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>subfolder.<span style="color: #006600;">Name</span> == <span style="color: #3366CC;">".svn"</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #000066; font-weight: bold;">continue</span>; <span style="color: #009900; font-style: italic;">// ignore .svn folders</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; findJavaScript<span style="color:#006600; font-weight:bold;">&#40;</span>subfolder<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> rootPath = <span style="color: #3366CC;">"src/main/javascript"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> rootFolder = fso.<span style="color: #006600;">GetFolder</span><span style="color:#006600; font-weight:bold;">&#40;</span>rootPath<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">findJavaScript<span style="color:#006600; font-weight:bold;">&#40;</span>rootFolder<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
</blockquote>
<p>Other tools will help you hunt this down too, and I am sure some of you have Perl/Ruby/Python one liners to do the same ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/finding-those-trailing-commas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintaining Browser Specific CSS</title>
		<link>http://ajaxian.com/archives/maintaining-css</link>
		<comments>http://ajaxian.com/archives/maintaining-css#comments</comments>
		<pubDate>Fri, 26 Sep 2008 11:35:46 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=4612</guid>
		<description><![CDATA[Nick Cairns saw our post on conditional CSS for browsers and followed up discussing how he handles maintaining IE specific CSS selectors:

We keep our IE related styling right below the common (standards-based) declarations.  BUT, we DON’T use hacks.  Underscore hacks, * hacks, and all of those things that we all gave up with [...]]]></description>
			<content:encoded><![CDATA[<p>Nick Cairns saw <a href="http://ajaxian.com/archives/conditional-css-inline-browser-specific-css">our post on conditional CSS for browsers</a> and followed up <a href="http://blog.niccai.com/post/51688182/maintainable-css-using-ie-specific-css-selectors">discussing how he handles maintaining IE specific CSS selectors</a>:</p>
<blockquote><p>
We keep our IE related styling right below the common (standards-based) declarations.  BUT, we DON’T use hacks.  Underscore hacks, * hacks, and all of those things that we all gave up with the birth of IE7 should remain dead and buried.  Instead, we’re going to use IE’s conditional commenting to create IE specific CSS selectors.  We do this by adding a conditional comment block as the outer most wrapper in our html template (ie. the first tag inside the <body>).</p>
<div class="igBar"><a href="javascript:showCodeTxt('html-39');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">HTML:</span>
<div id="html-39">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--[if IE 7]&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"body1"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"IE IE7 IE67"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>!<span style="color:#006600; font-weight:bold;">&#91;</span>endif<span style="color:#006600; font-weight:bold;">&#93;</span>--<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"body1"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"IE IE6 IE56 IE67"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>!<span style="color:#006600; font-weight:bold;">&#91;</span>endif<span style="color:#006600; font-weight:bold;">&#93;</span>--<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--[if IE 5]&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"body1"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"IE IE5 IE56"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;</span></a>!<span style="color:#006600; font-weight:bold;">&#91;</span>endif<span style="color:#006600; font-weight:bold;">&#93;</span>--<span style="color: #000000; font-weight: bold;">&gt;</span></a></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--[if !IE]&gt;</span></span>--&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"body1"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"W3C"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--&lt;![endif]--&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* THE REST OF YOUR HTML GOES HERE */</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>&nbsp; &nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Now, in this sample, we do have support for older legacy versions of IE, so you could always reduce the number of conditions if your project doesn’t need this level of support. And, you could also easily extend it to include IE8, or to do minus versioning such as IE8-.</p>
<p>With this conditional block in place, it becomes quite easy to place IE only style declarations right below their standards-based counterparts. As an example:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-40');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-40">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #cc00cc;">#header <span style="color:#006600; font-weight:bold;">&#123;</span></span> <span style="color: #000000; font-weight: bold;">overflow</span>: <span style="color: #993333;">hidden</span>; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #6666ff;">.IE </span><span style="color: #cc00cc;">#header <span style="color:#006600; font-weight:bold;">&#123;</span></span> zoom: <span style="color:#800000;">1</span>; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/maintaining-css/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Tip: Using a background image on an image</title>
		<link>http://ajaxian.com/archives/tip-using-a-background-image-on-an-image</link>
		<comments>http://ajaxian.com/archives/tip-using-a-background-image-on-an-image#comments</comments>
		<pubDate>Mon, 15 Sep 2008 10:23:38 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=4425</guid>
		<description><![CDATA[Pascal Opitz answered the question "Can you set an image background on an image element?" in simple fashion.
All you have to do is make sure that the image is display: block and has a padding.
He put up a simple demo that uses a div with an image, and he applies backgrounds to both:
PLAIN TEXT
CSS:




&#160;


div &#123;


&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Pascal Opitz answered the question <a href="http://www.contentwithstyle.co.uk/Blog/183/css-background-image-on-html-image-element">"Can you set an image background on an image element?"</a> in simple fashion.</p>
<p>All you have to do is make sure that the image is <code>display: block</code> and has a <code>padding</code>.</p>
<p>He put up a <a href="http://www.contentwithstyle.co.uk/resources/img_bg_demo/">simple demo</a> that uses a div with an image, and he applies backgrounds to both:</p>
<div class="igBar"><a href="javascript:showCodeTxt('css-42');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">CSS:</span>
<div id="css-42">
<div class="css">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">div <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">'blur.jpg'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">width</span>: 232px;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span>: 200px;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">img <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">display</span>: <span style="color: #993333;">block</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #993333;">url</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">'parallax.gif'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">bottom</span> <span style="color: #000000; font-weight: bold;">left</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">padding</span>: 93px 100px 75px 100px;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p><img src="http://ajaxian.com/wp-content/uploads/imagewithbg.png" alt="" title="Image with a CSS background image" width="228" height="196" class="alignnone size-full wp-image-4426" /></p>
<p>You have the little chap running as the actual src of the image, the animated background as the img background, and then the sky background applied to the div.</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/tip-using-a-background-image-on-an-image/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>addSizes.js: automatic link file-size generation</title>
		<link>http://ajaxian.com/archives/addsizesjs-automatic-link-file-size-generation</link>
		<comments>http://ajaxian.com/archives/addsizesjs-automatic-link-file-size-generation#comments</comments>
		<pubDate>Tue, 02 Sep 2008 10:07:19 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=4309</guid>
		<description><![CDATA[Nathalie Downe has taken Simon Willison's json-head App Engine mini-service and used it to create addSizes.js, a little script that looks for large files linked from a page, and automatically adds their file size to the copy after the link.
Once in place, you simple do your usual link, and asynchronously the Web page will be [...]]]></description>
			<content:encoded><![CDATA[<p>Nathalie Downe has taken Simon Willison's <a href="http://simonwillison.net/2008/Jul/29/jsonhead/">json-head</a> App Engine mini-service and used it to create <a href="http://natbat.net/2008/Aug/27/addSizes/">addSizes.js</a>, a little script that looks for large files linked from a page, and automatically adds their file size to the copy after the link.</p>
<p>Once in place, you simple do your usual link, and asynchronously the Web page will be updated to look like "your pdf link (pdf 2.8 MB)".</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-44');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-44">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">jQuery<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'a[href$=&quot;.pdf&quot;], a[href$=&quot;.doc&quot;], a[href$=&quot;.mp3&quot;], a[href$=&quot;.m4u&quot;]'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">each</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// looking at the href of the link, if it contains .pdf or .doc or .mp3</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> link = $<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> bits = <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">href</span>.<span style="color: #006600;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'.'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> type = bits<span style="color:#006600; font-weight:bold;">&#91;</span>bits.<span style="color: #006600;">length</span> -<span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> url= <span style="color: #3366CC;">"http://json-head.appspot.com/?url="</span>+<span style="color: #000066; font-weight: bold;">encodeURI</span><span style="color:#006600; font-weight:bold;">&#40;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color: #006600;">attr</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>+<span style="color: #3366CC;">"&amp;callback=?"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// then call the json thing and insert the size back into the link text</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; $.<span style="color: #006600;">getJSON</span><span style="color:#006600; font-weight:bold;">&#40;</span>url, <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>json.<span style="color: #006600;">ok</span> &amp;&amp; json.<span style="color: #006600;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'Content-Length'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> length = parseInt<span style="color:#006600; font-weight:bold;">&#40;</span>json.<span style="color: #006600;">headers</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'Content-Length'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// divide the length into its largest unit</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> units = <span style="color:#006600; font-weight:bold;">&#91;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1024</span> * <span style="color:#800000;">1024</span> * <span style="color:#800000;">1024</span>, <span style="color: #3366CC;">'GB'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1024</span> * <span style="color:#800000;">1024</span>, <span style="color: #3366CC;">'MB'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1024</span>, <span style="color: #3366CC;">'KB'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span>, <span style="color: #3366CC;">'bytes'</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i = <span style="color:#800000;">0</span>; i &lt;units.<span style="color: #006600;">length</span>; i++<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> unitSize = units<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> unitText = units<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>length&gt;= unitSize<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; length = length / unitSize;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// 1 decimal place</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; length = Math.<span style="color: #006600;">ceil</span><span style="color:#006600; font-weight:bold;">&#40;</span>length * <span style="color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span> / <span style="color:#800000;">10</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> lengthUnits = unitText;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// insert the text directly after the link and add a class to the link</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; link.<span style="color: #006600;">after</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">' ('</span> + type + <span style="color: #3366CC;">' '</span> + length + <span style="color: #3366CC;">' '</span> + lengthUnits + <span style="color: #3366CC;">')'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; link.<span style="color: #006600;">addClass</span><span style="color:#006600; font-weight:bold;">&#40;</span>type<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/addsizesjs-automatic-link-file-size-generation/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Using CSS to do the print watermark technique</title>
		<link>http://ajaxian.com/archives/using-css-to-do-the-print-watermark-technique</link>
		<comments>http://ajaxian.com/archives/using-css-to-do-the-print-watermark-technique#comments</comments>
		<pubDate>Wed, 27 Aug 2008 07:14:57 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=4243</guid>
		<description><![CDATA[Andy Pemberton has put together a simple solution to get the watermark technique to work nicely with print CSS.
Check out the sample and pull up a print preview. He details the good, bad, and ugly:

The Good
The first step to getting a printable watermark is to use an inline  tag, rather than background-images. In most [...]]]></description>
			<content:encoded><![CDATA[<p>Andy Pemberton has put together a simple solution to get the <a href="http://www.andypemberton.com/css/print-watermarks-with-css/">watermark technique to work nicely with print CSS</a>.</p>
<p>Check out the <a href="http://www.andypemberton.com/sandbox/watermark/">sample</a> and pull up a print preview. He details the good, bad, and ugly:</p>
<blockquote>
<h2>The Good</h2>
<p>The first step to getting a printable watermark is to use an inline <code><img /></code> tag, rather than background-images. In most browsers, background-images won’t be printed unless the user selects an additional browser option to enable it.</p>
<p>From here, we need to place the watermark image so that it is repeated on each page. It looks like the <a onclick="javascript:urchinTracker ('/outgoing/www.w3.org/TR/CSS21/visuren.html#fixed-positioning');" href="http://www.w3.org/TR/CSS21/visuren.html#fixed-positioning">W3C thought of this ahead of time in the positioning module</a>. The position property’s fixed value should ensure that a watermark is printed on each page. Some browsers, like FireFox and Internet Explorer 7, apply this rule correctly.</p>
<h2>The Bad</h2>
<p>Not all browsers play nicely with <code>position:fixed</code> and we haven’t yet considered using z-indexing to ensure the watermark displays behind all the regular page content. For IE and FireFox 3+, simply applying <code>z-index:-1</code> to the watermark will do the trick.</p>
<p>Though, it turns out that earlier versions of FireFox (and other Gecko-based browsers) don’t play nicely with negative z-indexing. So, my current approach uses a few Gecko-specific hacks to degrade the watermark approach for FireFox 2. For FireFox 2, the watermark will display over the content, but still display on every page. Unfortunately, this means the <em>CSS for my approach doesn’t validate</em>.</p>
<h2>The Ugly</h2>
<p>But of course, position:fixed isn’t supported at all in IE6; it appears to ignore the rule altogether and display the image inline. So, I use conditional comments to filter just a *few* IE6-specific hacks:</p>
<p><code><!--[if lt IE 7]></code></p>
<link rel="stylesheet" type="text/css" media="print" href="styles/watermark-print-ie.css" />
< ![endif]--></p>
<p>Absolute positioning and an additional 100% height on the watermark and printable content are the keys to getting this working for IE6:</p>
<p><code>div.watermark{<br />
	position:absolute;<br />
	overflow:hidden;<br />
}<br />
div.content{<br />
	height:100%;</p>
<p>}</code></p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/using-css-to-do-the-print-watermark-technique/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
