<?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>Code Couch &#187; Jeff</title>
	<atom:link href="http://www.codecouch.com/author/jeff/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codecouch.com</link>
	<description>The ramblings of two code monkeys</description>
	<lastBuildDate>Thu, 19 Nov 2009 15:47:59 +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>Speed up your Javascript</title>
		<link>http://www.codecouch.com/2009/01/speed-up-your-javascript/</link>
		<comments>http://www.codecouch.com/2009/01/speed-up-your-javascript/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 12:31:38 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=248</guid>
		<description><![CDATA[Nicolas Zakas (of Professional JavaScript, Second Edition fame) has a series of articles discussing improving Javascript performance - avoiding browsers complaining about long-running scripts. Some useful suggestions on how to optimise and chunk interactions.]]></description>
			<content:encoded><![CDATA[<p>I came across some very interesting and informative articles on Javascript performance improvement from Nicolas Zakas (the author of the newly released <strong>Professional JavaScript, Second Edition</strong> book):</p>
<ul>
<li><a href="http://www.nczonline.net/blog/2009/01/13/speed-up-your-javascript-part-1/">Speed up your Javascript part 1</a></li>
<li><a href="http://www.nczonline.net/blog/2009/01/20/speed-up-your-javascript-part-2/">Speed up your Javascript part 2</a></li>
</ul>
<p>This is an ongoing series of articles with specific Javascript examples that make sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2009/01/speed-up-your-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use CSS pseudo classes to enhance accessibility</title>
		<link>http://www.codecouch.com/2009/01/use-css-pseudo-classes-to-enhance-accessibility/</link>
		<comments>http://www.codecouch.com/2009/01/use-css-pseudo-classes-to-enhance-accessibility/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 14:42:16 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=246</guid>
		<description><![CDATA[It is very simple to add some CSS rules to make your site more accessible. Read on to find out how you can use pseudo classes to provide extra support for keyboard users in all browsers (including Internet Explorer).]]></description>
			<content:encoded><![CDATA[<p>CSS pseudo-classes are probably not something most people are familiar with &#8211; although many developers would make use of them without necessarily being aware of it! When you hover the mouse over a link, many sites will underline the link for you. This is using the <strong>hover</strong> pseudo-class.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript" style="color: #000000;">a <span class="br0">&#123;</span> text<span class="sy0">-</span>decoration<span class="sy0">:</span>none<span class="sy0">;</span> <span class="br0">&#125;</span>
a<span class="sy0">:</span>hover <span class="br0">&#123;</span> text<span class="sy0">-</span>decoration<span class="sy0">:</span>underline<span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div></div>

<p>The above example sets all anchors to have no underline text decoration, and the <strong>hover</strong> pseudo-class sets all anchors to have an underline on them. When the user hovers their mouse over a link, an underline will show under the link. When they move their mouse away, the <strong>hover</strong> pseudo-class stops taking effect and the underline is removed.</p>
<p>Pseudo-classes are supported with all modern browsers, but this support is only for the anchor element. Any attempt to use a pseudo-class on any other element will not work in Internet Explorer 6.</p>
<p>There are other pseudo-classes that can be used to provide a more usable experience for those that primarily use a keyboard to navigation through a page.  The first of these is the <strong>focus</strong> pseudo-class (which take affect when the element gains focus &#8211; such as tabbing to the element). This pseudo-class can be used to style elements when they receive focus.</p>
<p>Building on the initial example, the addition of a <strong>focus</strong> pseudo-class will ensure that the same hover effects (in this case some underline text decoration) are applied when the user tabs focus to the anchor.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript" style="color: #000000;">a <span class="br0">&#123;</span> text<span class="sy0">-</span>decoration<span class="sy0">:</span>none<span class="sy0">;</span> <span class="br0">&#125;</span>
a<span class="sy0">:</span>hover<span class="sy0">,</span> a<span class="sy0">:</span><span class="kw3">focus</span> <span class="br0">&#123;</span> text<span class="sy0">-</span>decoration<span class="sy0">:</span>underline<span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div></div>

<p>This would be fine, except that Internet Explorer 6 doesn&#8217;t understand the <strong>focus</strong> pseudo-class at all! The solution is to use the <strong>active</strong> pseudo-class to extend the CSS rule.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript" style="color: #000000;">a <span class="br0">&#123;</span> text<span class="sy0">-</span>decoration<span class="sy0">:</span>none<span class="sy0">;</span> <span class="br0">&#125;</span>
a<span class="sy0">:</span>hover<span class="sy0">,</span> a<span class="sy0">:</span><span class="kw3">focus</span><span class="sy0">,</span> a<span class="sy0">:</span>active <span class="br0">&#123;</span> text<span class="sy0">-</span>decoration<span class="sy0">:</span>underline<span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div></div>

<p>The order of the<strong> pseudo-class </strong>rules is important (and if you get the order wrong, you may experience some of the CSS rules displaying inconsistently across browsers). As a general rule, always put pseudo-classes in the following order:</p>
<blockquote><p><strong>link, visited, hover, focus, active</strong></p></blockquote>
<p>So, whenever you define a <strong>hover</strong> pseudo-class CSS rule, consider adding in a <strong>focus</strong> and then an <strong>active</strong> pseudo-class at the same time &#8211; it will help users that choose to use the keyboard to navigate your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2009/01/use-css-pseudo-classes-to-enhance-accessibility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do you vertically centre content using CSS?</title>
		<link>http://www.codecouch.com/2008/10/how-do-you-vertically-centre-content-using-css/</link>
		<comments>http://www.codecouch.com/2008/10/how-do-you-vertically-centre-content-using-css/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 13:12:07 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=201</guid>
		<description><![CDATA[Find out how to do vertical centring (vertical alignment) of content using just CSS (and some div elements).]]></description>
			<content:encoded><![CDATA[<p>How do you vertical centre some content using CSS (and some extra div elements)? This is the same simple layout that used to be achieved using a table and valign attribute. This solution doesn&#8217;t require a table at all (but it does require some extra div elements &#8211; as per the markup below).</p>
<p>With the following markup:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict" style="color: #000000;"><span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;verticalCenteringOuter&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;moduleA&quot;</span><span class="kw2">&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;verticalCenteringMiddle&quot;</span><span class="kw2">&gt;</span></span>
		<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;verticalCenteringInner&quot;</span><span class="kw2">&gt;</span></span>
			<span class="sc2"><span class="kw2">&lt;b&gt;</span></span>Some vertical aligned content here<span class="sc2"><span class="kw2">&lt;/b&gt;</span></span>
		<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span></pre></div></div></div>

<p>Using the following CSS:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">&lt;style type=<span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
<span class="re0">#moduleA</span> <span class="br0">&#123;</span>
	<span class="kw1">height</span><span class="sy0">:</span> <span class="re3">300px</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.verticalCenteringOuter</span> <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> table<span class="sy0">;</span>
	<span class="kw1">overflow</span><span class="sy0">:</span> <span class="kw2">hidden</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.verticalCenteringMiddle</span> <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">table-cell</span><span class="sy0">;</span>
	<span class="kw1">vertical-align</span><span class="sy0">:</span> <span class="kw2">middle</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span>
&nbsp;
&lt;!--<span class="br0">&#91;</span>if IE<span class="br0">&#93;</span><span class="sy0">&gt;</span>
&lt;style type=<span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
<span class="re1">.verticalCenteringOuter</span> <span class="br0">&#123;</span>
	<span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">relative</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.verticalCenteringMiddle</span> <span class="br0">&#123;</span>
	<span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">absolute</span><span class="sy0">;</span>
	<span class="kw1">top</span><span class="sy0">:</span> <span class="re3"><span class="nu0">50</span>%</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.verticalCenteringInner</span> <span class="br0">&#123;</span>
	<span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">relative</span><span class="sy0">;</span>
	<span class="kw1">top</span><span class="sy0">:</span> -<span class="re3"><span class="nu0">50</span>%</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span>
&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>--<span class="sy0">&gt;</span></pre></div></div></div>

<p>Full credit on this to <a href="http://www.jakpsatweb.cz/css/css-vertical-center-solution.html">Yuhů (www.jakpsatweb.cz)</a>. Thanks for the inspiration on this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/how-do-you-vertically-centre-content-using-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems tabbing through checkboxes and radios in MacOSX Safari</title>
		<link>http://www.codecouch.com/2008/10/problems-tabbing-through-checkboxes-and-radios-in-macosx-safari/</link>
		<comments>http://www.codecouch.com/2008/10/problems-tabbing-through-checkboxes-and-radios-in-macosx-safari/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 12:45:34 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=199</guid>
		<description><![CDATA[Many people find it easier to use the tab key to cycle through the various fields of a form in a web page. If you are using a browser in MacOSX, you will find that you cannot use the tab key to access checkboxes or radio buttons... instead you have to use the mouse/trackpad. Read on for a solution.]]></description>
			<content:encoded><![CDATA[<p>Many people find it easier to use the tab key to cycle through the various fields of a form in a web page. This is a well supported and adopted behaviour &#8211; yet if you are using a browser in MacOSX, you will find that you cannot use the tab key to access checkboxes or radio buttons&#8230; instead you have to use the mouse/trackpad.</p>
<p>The solution is rather trivial &#8211; and also very simple to achieve.</p>
<p>Open the System Preferences application and choose Keyboard &#038; Mouse then change the Keyboard Shortcuts option to &#8220;All controls&#8221; (this can also be toggled using Control-Function-F7 if you are so inclined).</p>
<p>You can now use the tab key to cycle through checkboxes (use the spacebar to select a checkbox when you have cycled to it) and radio buttons (you can use up/down or left/right arrow keys to toggle a radio button when the group is in focus).</p>
<p>A similar option is available in Safari (MacOSX as well as Windows) in the Preferences menu option (within the Edit menu). Select the Advanced tab and select &#8220;Press Tab to highlight each item on a webpage&#8221;. When enabled, this option allows you to cycle through all elements that can receive focus using option+tab (this includes standard links on the page as well).</p>
<p>I&#8217;d like to credit this &#8220;discovery&#8221; to Brad Jasper and Dylan Ryan at <a href="http://www.mactips.org/archives/2008/04/30/tab-through-checkboxes-and-radio-buttons-in-safari/"> MacTips: Tips &#038; Tricks</a> &#8211; but the post is no longer available. Thanks for the heads-up guys!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/problems-tabbing-through-checkboxes-and-radios-in-macosx-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problems with anchors and alpha transparency filters in IE6</title>
		<link>http://www.codecouch.com/2008/10/problems-with-anchors-and-alpha-transparency-filters-in-ie6/</link>
		<comments>http://www.codecouch.com/2008/10/problems-with-anchors-and-alpha-transparency-filters-in-ie6/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 06:29:40 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=195</guid>
		<description><![CDATA[If you use the Microsoft filter CSS property to allow support for an alpha transparent PNG on an element, any links directly within that element are not clickable (in Internet Explorer 6 only). The problem is explained and a solution put forward that will make your links clickable again.]]></description>
			<content:encoded><![CDATA[<p>You can use alpha transparent PNGs in IE6 as described in <a href="http://www.codecouch.com/2007/05/how-do-i-display-alpha-transparent-pngs-across-all-browsers/">How do I display alpha transparent PNGs across all browsers</a>. There is a problem with implementing this solution &#8211; in Internet Explorer 6 links are no longer clickable when they are contained within an element with an alpha transparency filter applied.</p>
<div class="seeThrough h2Pod "><div class="seeThroughTop"><span class="tl"></span><span class="tr"></span><span class="t"></span></div><div class="seeThroughMiddle"><span class="r"></span><span class="l"></span><span class="m"></span><div class="seeThroughContent">
	<h2>The problem</h2>
</div></div><div class="seeThroughBottom"><span class="bl"></span><span class="br"></span><span class="b"></span></div></div>

<p>Consider the following CSS and HTML code snippets that set up the problem with a link contained within a div that has an alpha transparency filter applied to it:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">&lt;style type=<span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
<span class="re1">.opaque</span> <span class="br0">&#123;</span> <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">images/alphaTransparent<span class="re1">.png</span></span><span class="br0">&#41;</span> <span class="kw2">transparent</span> <span class="kw2">no-repeat</span> <span class="kw1">left</span> <span class="kw1">top</span><span class="sy0">;</span> <span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span>
&lt;!--<span class="br0">&#91;</span>if IE <span class="nu0">6</span><span class="br0">&#93;</span><span class="sy0">&gt;</span>
&lt;style type=<span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
<span class="re1">.opaque</span> <span class="br0">&#123;</span>
	<span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span>
	filter<span class="sy0">:</span> progid<span class="re2">:DXImageTransform</span><span class="re1">.Microsoft</span><span class="re1">.AlphaImageLoader</span><span class="br0">&#40;</span>enabled=true,sizingMethod=<span class="kw2">crop</span>,src=images/alphaTransparent<span class="re1">.png</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span>
&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>--<span class="sy0">&gt;</span></pre></div></div></div>


<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict" style="color: #000000;">...
<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;parent&quot;</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;opaque&quot;</span><span class="kw2">&gt;</span></span>
    <span class="sc2"><span class="kw2">&lt;span</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;child&quot;</span><span class="kw2">&gt;</span></span>Lorem <span class="sc2"><span class="kw2">&lt;a</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;http://www.codecouch.com&quot;</span><span class="kw2">&gt;</span></span>ipsum<span class="sc2"><span class="kw2">&lt;/a&gt;</span></span> dolor.<span class="sc2"><span class="kw2">&lt;/span&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
...</pre></div></div></div>

<p>The parent element has a class <b>opaque</b> applied to it which puts an image on the background of the element. In Internet Explorer 6 only, the background image is removed and the proprietary filter property is used. The link inside the child span is no longer clickable in Internet Explorer 6.</p>
<div class="seeThrough h2Pod "><div class="seeThroughTop"><span class="tl"></span><span class="tr"></span><span class="t"></span></div><div class="seeThroughMiddle"><span class="r"></span><span class="l"></span><span class="m"></span><div class="seeThroughContent">
	<h2>The solution</h2>
</div></div><div class="seeThroughBottom"><span class="bl"></span><span class="br"></span><span class="b"></span></div></div>

<p>Make sure the parent element (the element with the filter applied to it) doesn&#8217;t have the position property set on it, and the child element (the element with the link in it) has to have relative position.</p>
<p>The following addition to the above code will make the link clickable:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">&lt;!--<span class="br0">&#91;</span>if IE <span class="nu0">6</span><span class="br0">&#93;</span><span class="sy0">&gt;</span>
&lt;style type=<span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
<span class="re0">#child</span> <span class="br0">&#123;</span> <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">relative</span><span class="sy0">;</span> <span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span>
&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>--<span class="sy0">&gt;</span></pre></div></div></div>

<p>Since it only has to apply for Internet Explorer 6, the &#8220;fix&#8221; can be enclosed within the <a href="http://www.codecouch.com/2007/04/how-to-target-specific-ie-browsers-using-just-html/">conditional comment</a> that targets just that browser. This doesn&#8217;t require any javascript to work (unlike <a href="http://bjorkoy.com/past/2007/4/8/the_easiest_way_to_png/">other solutions</a> that have been posted) and degrades properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/problems-with-anchors-and-alpha-transparency-filters-in-ie6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create rollovers without using Javascript</title>
		<link>http://www.codecouch.com/2008/10/create-rollovers-without-using-javascript/</link>
		<comments>http://www.codecouch.com/2008/10/create-rollovers-without-using-javascript/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 13:11:10 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=174</guid>
		<description><![CDATA[Using just CSS, you can do simple (and more complex) rollovers... no javascript required. This post shows how to apply this technique to your own pages with ease - whether it's a colour change or a more complex image swap.]]></description>
			<content:encoded><![CDATA[<p>You can make use of the <b>:hover</b> pseudo class on the anchor tag to change the anchor&#8217;s style attributes. Typically you see this on sites that underline anchors when you mouse over them (when you hover over them). The CSS code to do this simple underlining can look like this:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">a <span class="br0">&#123;</span> <span class="kw1">text-decoration</span><span class="sy0">:</span> <span class="kw2">none</span><span class="sy0">;</span> <span class="br0">&#125;</span>
a<span class="re2">:hover</span> <span class="br0">&#123;</span> <span class="kw1">text-decoration</span><span class="sy0">:</span> <span class="kw2">underline</span><span class="sy0">;</span> <span class="br0">&#125;</span></pre></div></div></div>

<p>We could extend this to change the background and forground colour of the link to make it appear a little more &#8220;box-like&#8221; using something like this CSS code:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">a <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span>
	<span class="kw1">padding</span><span class="sy0">:</span> <span class="re3">5px</span> <span class="re3">10px</span><span class="sy0">;</span>
	<span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#<span class="nu0">000000</span></span><span class="sy0">;</span>
	<span class="kw1">color</span><span class="sy0">:</span> <span class="re0">#FFFFFF</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
a<span class="re2">:hover</span> <span class="br0">&#123;</span>
	<span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#CCCCCC</span><span class="sy0">;</span>
	<span class="kw1">color</span><span class="sy0">:</span> <span class="re0">#<span class="nu0">000000</span></span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div></div>

<p>If you wanted to have a background image on the anchor, then you could change the background-image when you hovered over the anchor. The CSS code might look like this:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">a <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span>
	<span class="kw1">padding</span><span class="sy0">:</span> <span class="re3">5px</span> <span class="re3">10px</span><span class="sy0">;</span>
	<span class="kw1">background</span><span class="sy0">:</span> <span class="re0">#<span class="nu0">000000</span></span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">img/anchor_off<span class="re1">.gif</span></span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">left</span> <span class="kw1">top</span><span class="sy0">;</span>
	<span class="kw1">color</span><span class="sy0">:</span> <span class="re0">#FFFFFF</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
a<span class="re2">:hover</span> <span class="br0">&#123;</span>
	<span class="kw1">background</span><span class="sy0">:</span> <span class="re0">#CCCCCC</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">img/anchor_hovered<span class="re1">.gif</span></span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">left</span> <span class="kw1">top</span><span class="sy0">;</span>
	<span class="kw1">color</span><span class="sy0">:</span> <span class="re0">#<span class="nu0">000000</span></span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div></div>

<p>This technique does suffer from a flaw, however. You will invariably see a flickering as you roll over the anchor for the first time due to the browser having to request the second image (assuming the file isn&#8217;t already in the browser cache).</p>
<p>This problem can be fixed by using the same image for both the normal and hover state of the anchor &#8211; just reposition the background image on hover. This is presented very well over at <a href="http://www.alistapart.com/articles/sprites/">A List Apart</a> where Dave Shea introduces the concept of CSS Sprites. The image below (195px wide, 30px high in size) shows how you might set this up:</p>
<p><img src="http://www.codecouch.com/wp-content/uploads/2008/10/cssbuttonbackground.gif" alt="" title="Anchor background sprites" width="195" height="30" /></p>
<p>The image above shows both states of the anchor&#8230; the initial state at the &#8220;left top&#8221; and the hovered state &#8220;100px&#8221; from the left of the image. The following CSS code shows how you can reposition the background image to show a different image on hover &#8211; without the flicker:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">a <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span>
	<span class="kw1">padding</span><span class="sy0">:</span> <span class="re3">5px</span> <span class="re3">10px</span><span class="sy0">;</span>
	<span class="kw1">width</span><span class="sy0">:</span> <span class="re3">95px</span><span class="sy0">;</span>
	<span class="kw1">height</span><span class="sy0">:</span> <span class="re3">30px</span><span class="sy0">;</span>
	<span class="kw1">overflow</span><span class="sy0">:</span> <span class="kw2">hidden</span><span class="sy0">;</span>
	<span class="kw1">background</span><span class="sy0">:</span> <span class="re0">#<span class="nu0">000000</span></span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">img/anchor_background<span class="re1">.gif</span></span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">left</span> <span class="kw1">top</span><span class="sy0">;</span>
	<span class="kw1">color</span><span class="sy0">:</span> <span class="re0">#FFFFFF</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
a<span class="re2">:hover</span> <span class="br0">&#123;</span>
	<span class="kw1">background-position</span><span class="sy0">:</span> <span class="re3">100px</span> <span class="kw1">top</span><span class="sy0">;</span>
	<span class="kw1">background-color</span><span class="sy0">:</span> <span class="re0">#CCCCCC</span><span class="sy0">;</span>
	<span class="kw1">color</span><span class="sy0">:</span> <span class="re0">#<span class="nu0">000000</span></span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div></div>

<p>You may have to deal with all the anchor pseudo classes to get the effect consistent in all browsers, and be sure to define them in the correct order&#8230; :link, :visited, :hover, :active.</p>
<p>Finally, Internet Explorer only supports pseudo classes on the anchor element. All other browsers support pseudo classes on all elements. You could use this technique on non-anchor elements, but would be forced to introduce some javascript to support Internet Explorer. A good working example of this is the popular <a href="http://www.alistapart.com/articles/dropdowns">Suckerfish dropdowns</a> CSS menu solution that uses :hover on the list item element and attaches some javascript for Internet Explorer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/create-rollovers-without-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling cross-site scripting XSS via an iframe</title>
		<link>http://www.codecouch.com/2008/10/cross-site-scripting-xss-using-iframes/</link>
		<comments>http://www.codecouch.com/2008/10/cross-site-scripting-xss-using-iframes/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 12:24:41 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Iframe]]></category>
		<category><![CDATA[XSS]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=173</guid>
		<description><![CDATA[Communication from an iframe that has content from a domain other than the one the iframe is contained within is a constant source of frustration - as browsers prevent this kind of activity due to built-in security policies. Here is a technique to perform cross-site scripting (XSS) in just such an environment with example code and a real-world example.]]></description>
			<content:encoded><![CDATA[<p>The scenario is relatively common &#8211; you have a page that contains an iframe pointing to some content hosted on another domain. Nothing wrong with this &#8211; iframes were designed with this in mind! The following diagram shows the sort of setup we are talking about.</p>
<p><img class="size-full wp-image-176" title="Iframed content diagram" src="http://www.codecouch.com/wp-content/uploads/2008/10/xssdiagraminitial.gif" alt="Diagram showing an iframe within a web page" width="394" height="186" /></p>
<p>Now you want to click a link within the iframe content and have that perform some action on the parent page (maybe you want to submit a form on the parent page, maybe you want to adjust the height of the iframe on the parent page). And you start getting frustrated because the browser won&#8217;t let you access all your javascript functions/properties on another domain.</p>
<p>Communication from an iframe that has content from a domain other than the one the iframe is contained within is a constant source of frustration &#8211; as browsers prevent this kind of activity due to built-in security policies. The solution is actually relatively painless requiring the addition of an iframe (see the following diagram).</p>
<p><img class="size-full wp-image-172" title="XSS Diagram" src="http://www.codecouch.com/wp-content/uploads/2008/10/xssdiagram.gif" alt="Diagram showing page structure for XSS via an iframe" width="394" height="186" /></p>
<div class="seeThrough h2Pod "><div class="seeThroughTop"><span class="tl"></span><span class="tr"></span><span class="t"></span></div><div class="seeThroughMiddle"><span class="r"></span><span class="l"></span><span class="m"></span><div class="seeThroughContent">
	<h2>Real world example</h2>
</div></div><div class="seeThroughBottom"><span class="bl"></span><span class="br"></span><span class="b"></span></div></div>

<p>You can see a working example of this over at <a href="http://movies.sky.com/cinema-finder" title="Sky Movies cinema finder page">Sky Movies</a> where the iframe is resized as the content within the iframe changes. This is being controlled from within the iframe.</p>
<p>Why do we need to implement a solution like this in the first place?</p>
<p>Because whilst the main page at movies.sky.com can set the height of the iframe, it cannot get the height of the iframe content&#8230; and the iframe document can get it&#8217;s height but it can&#8217;t set the height of it&#8217;s enclosing iframe.</p>
<div class="seeThrough h2Pod "><div class="seeThroughTop"><span class="tl"></span><span class="tr"></span><span class="t"></span></div><div class="seeThroughMiddle"><span class="r"></span><span class="l"></span><span class="m"></span><div class="seeThroughContent">
	<h2>An explaination of each component of the solution</h2>
</div></div><div class="seeThroughBottom"><span class="bl"></span><span class="br"></span><span class="b"></span></div></div>

<p>Using the following example pages, we can create a demonstration of this technique. Following is the source of the main page (marked as [1] in the figure above) which contains the iframe and the function that will be used to resize the iframe.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict" style="color: #000000;"><span class="sc2"><span class="kw2">&lt;html&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;head&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;title&gt;</span></span>Page hosted on example.com<span class="sc2"><span class="kw2">&lt;/title&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="kw2">&gt;</span></span>
	function resizeIframeHeight(nHeight) {
		var iframe = document.getElementById('mainIframe');
		iframe.setAttribute('height', nHeight);
	}
	<span class="sc2"><span class="kw2">&lt;/script&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/head&gt;</span></span>
&nbsp;
<span class="sc2"><span class="kw2">&lt;body&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;h1&gt;</span></span>This page is hosted on the example.com domain<span class="sc2"><span class="kw2">&lt;/h1&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;p&gt;</span></span>The iframe below is hosted on the example.org domain<span class="sc2"><span class="kw2">&lt;/p&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;iframe</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;mainIframe&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;400&quot;</span> <span class="kw3">height</span><span class="sy0">=</span><span class="st0">&quot;200&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://example.org/iframedDocument.html&quot;</span><span class="kw2">&gt;</span></span>Iframes not supported.<span class="sc2"><span class="kw2">&lt;/iframe&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/body&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/html&gt;</span></span></pre></div></div></div>

<p>Following is the source of the iframe page (marked as [2] in the figure above) which contains the extra iframe and some javascript that allows this technique to work.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict" style="color: #000000;"><span class="sc2"><span class="kw2">&lt;html&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;head&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;title&gt;</span></span>Page hosted on example.org<span class="sc2"><span class="kw2">&lt;/title&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="kw2">&gt;</span></span>
	function updateIframeHeight() {
		var iframe = document.getElementById('hiddenIframe');
		var newHeight = parseInt(document.body.offsetHeight,10) + 10;
		iframe.src = 'http://example.com/xssEnabler.html?height=' + newHeight;
	}
	<span class="sc2"><span class="kw2">&lt;/script&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/head&gt;</span></span>
&nbsp;
<span class="sc2"><span class="kw2">&lt;body</span> <span class="kw3">onload</span><span class="sy0">=</span><span class="st0">&quot;updateIframeHeight()&quot;</span><span class="kw2">&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;h1&gt;</span></span>This page is hosted on the example.org domain<span class="sc2"><span class="kw2">&lt;/h1&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;p&gt;</span></span>The iframe below is hosted on the example.com domain (and be styled to be hidden)<span class="sc2"><span class="kw2">&lt;/p&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;iframe</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;hiddenIframe&quot;</span> <span class="kw3">width</span><span class="sy0">=</span><span class="st0">&quot;100&quot;</span> <span class="kw3">height</span><span class="sy0">=</span><span class="st0">&quot;100&quot;</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;http://example.com/xssEnabler.html&quot;</span><span class="kw2">&gt;</span></span>Iframes not supported.<span class="sc2"><span class="kw2">&lt;/iframe&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/body&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/html&gt;</span></span></pre></div></div></div>

<p>The final source file resides on the original domain (marked as [3] in the figure above) and contains some javascript to strip out the height parameter and then pass this on to the function on the main page that resizes the iframe. It is referred to in the code above, as the content of the file at http://example.org/xssEnabler.html &#8211; and whilst it is saved as a .html file, it contains just the code you see below.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript" style="color: #000000;"><span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="sy0">&gt;</span>
	<span class="kw2">function</span> getFirstParamFromLocation<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		<span class="kw2">var</span> pair <span class="sy0">=</span> window.<span class="me1">location</span>.<span class="me1">search</span>.<span class="me1">substring</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="kw2">var</span> parts <span class="sy0">=</span> pair.<span class="me1">split</span><span class="br0">&#40;</span><span class="st0">'='</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="kw1">return</span> parts<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
	<span class="kw2">var</span> nHeight <span class="sy0">=</span> getFirstParamFromLocation<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw1">try</span> <span class="br0">&#123;</span>
		window.<span class="me1">top</span>.<span class="me1">resizeIframeHeight</span><span class="br0">&#40;</span>height<span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="br0">&#125;</span> <span class="kw1">catch</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><span class="sy0">;</span>
<span class="sy0">&lt;/</span>script<span class="sy0">&gt;</span></pre></div></div></div>

<p>Obviously you would not be using example.com and example.org for your solution, they are used merely to identify the different domains you would use for each file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/cross-site-scripting-xss-using-iframes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to use “clearfix” CSS to clear floats without markup</title>
		<link>http://www.codecouch.com/2008/10/how-to-use-clearfix-css-to-clear-floats-without-markup/</link>
		<comments>http://www.codecouch.com/2008/10/how-to-use-clearfix-css-to-clear-floats-without-markup/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 21:43:19 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Front-end]]></category>
		<category><![CDATA[HTML/XHTML]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=165</guid>
		<description><![CDATA[Here we extended the normal rules for clearfix and provide a complete CSS solution to clearing floated elements (ensuring that a parent element inherits it's floated child element's height). A complete clearfix redux.]]></description>
			<content:encoded><![CDATA[<p>When an element is floated, it is taken out of the normal flow of the document. As a result, the element takes up no height (in the normal flow) &#8211; and any wrapping parent element will not automatically resize to accommodate the height of the floated element. Here is some sample HTML that shows this in it&#8217;s simple form:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict" style="color: #000000;">...
<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;parent&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;background-color:#F00;&quot;</span><span class="kw2">&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;child&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;float: left;&quot;</span><span class="kw2">&gt;</span></span>Floated element<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
...</pre></div></div></div>

<p>Given the child element is floated, it doesn&#8217;t affect the height of the parent element &#8211; and so the parent element remains with no height (and the red background colour is never shown).</p>
<p>The <a href="http://www.w3.org/TR/CSS2/visuren.html#floats">W3 describe floating an element</a> and the use of a &#8220;clearing element&#8221; (a block level element with the <b>clear</b> CSS property set). This is not acceptable for all layouts. It would be nicer if all this could be carried out using CSS &#8211; providing a separation of content and layout into the bargain.</p>
<p>Rather than attempt to merely re-word much of what is already online, you can read about how the CSS for this works in more detail at <a href="http://www.positioniseverything.net/easyclearing.html">Position is Everything</a>. Whilst their implementation is slightly different to the one presented below, their description is excellent (and they are credited with bringing together all the threads to make this solution usable).</p>
<p>The <b>clearfix</b> solution below is our current &#8220;best practise&#8221; effort to date. We have switched from using the typical &#8220;.&#8221; to using a space &#8221; &#8221; in the <b>content</b> rule due to <a href="http://perishablepress.com/press/2008/02/05/lessons-learned-concerning-the-clearfix-css-hack/">reports of some layout issues in Firefox</a>.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css" style="color: #000000;">&lt;style type=<span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
<span class="re1">.clearfix</span><span class="re2">:after</span> <span class="br0">&#123;</span>
	<span class="kw1">clear</span><span class="sy0">:</span> <span class="kw2">both</span><span class="sy0">;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span>
	<span class="kw1">content</span><span class="sy0">:</span> <span class="st0">&quot; &quot;</span><span class="sy0">;</span>
	<span class="kw1">height</span><span class="sy0">:</span> <span class="re3">0px</span><span class="sy0">;</span>
	<span class="kw1">visibility</span><span class="sy0">:</span> <span class="kw2">hidden</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.clearfix</span> <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> inline-<span class="kw2">block</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="coMULTI">/* Hide these rules from IE-mac \*/</span>
* html <span class="re1">.clearfix</span> <span class="br0">&#123;</span>
	<span class="kw1">height</span><span class="sy0">:</span> <span class="re3"><span class="nu0">1</span>%</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="re1">.clearfix</span> <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">block</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
li<span class="re1">.clearfix</span> <span class="br0">&#123;</span>
	<span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">list-item</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="coMULTI">/* End hide from IE-mac */</span>
&lt;/style<span class="sy0">&gt;</span></pre></div></div></div>

<p>We extended the normal rules to include setting the correct display (list-item) for use on list items (as a direct result of some problems with floated lists). If you don&#8217;t care about IE-mac support (don&#8217;t forget that <a href="http://www.codecouch.com/2005/12/microsoft-finally-retires-ie-5-for-the-mac/">Microsoft finally retired IE 5 for the Mac</a>) then you can avoid using the &#8220;commented backslash hack&#8221; all together.</p>
<p>Going back to our original HTML code, we can place the <b>clearfix</b> class on the parent element to ensure that it inherits the height of it&#8217;s floating child elements (and the red background will now show):</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict" style="color: #000000;">...
<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">class</span><span class="sy0">=</span><span class="st0">&quot;clearfix&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;parent&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;background-color:#F00;&quot;</span><span class="kw2">&gt;</span></span>
	<span class="sc2"><span class="kw2">&lt;div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;child&quot;</span> <span class="kw3">style</span><span class="sy0">=</span><span class="st0">&quot;float: left;&quot;</span><span class="kw2">&gt;</span></span>Floated element<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
<span class="sc2"><span class="kw2">&lt;/div&gt;</span></span>
...</pre></div></div></div>

<p>You can read more about the <b>clearfix</b> solution all over the place, including:</p>
<ul>
<li><a href="http://www.positioniseverything.net/easyclearing.html">Position is Everything</a></li>
<li><a href="http://www.456bereastreet.com/archive/200603/new_clearing_method_needed_for_ie7/">456 Berea Street</a></li>
<li><a href="http://www.sitepoint.com/blogs/2005/02/26/simple-clearing-of-floats/">Sitepoint</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/how-to-use-clearfix-css-to-clear-floats-without-markup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ReferenceError: console is not defined</title>
		<link>http://www.codecouch.com/2008/10/referenceerror-console-is-not-defined/</link>
		<comments>http://www.codecouch.com/2008/10/referenceerror-console-is-not-defined/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 19:50:30 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=162</guid>
		<description><![CDATA[If you have recently upgraded to the free Firefox extension Firebug 1.2 - then you may have experienced some difficulties with console.log throwing the following: ReferenceError: console is not defined. Read on for an explaination...]]></description>
			<content:encoded><![CDATA[<p>If you have recently changed your Firefox configurations (and upgraded to Firebug 1.2) then you may have experienced some difficulties with console.log throwing the following error:</p>
<blockquote><p>ReferenceError: console is not defined</p></blockquote>
<p>It turns out that this is by design. If you want to make use of the console object that Firebug offers, you need to do so with a call to <strong>window.loadFirebugConsole()</strong> first.</p>
<p>A little bit of testing, and the following code can be safely put in your javascript source to enable use of the Firebug console object safely (without breaking other browsers).</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript" style="color: #000000;"><span class="kw1">if</span> <span class="br0">&#40;</span>window<span class="br0">&#91;</span><span class="st0">'loadFirebugConsole'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	window.<span class="me1">loadFirebugConsole</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
	<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>window<span class="br0">&#91;</span><span class="st0">'console'</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		window.<span class="me1">console</span> <span class="sy0">=</span> <span class="br0">&#123;</span><span class="br0">&#125;</span><span class="sy0">;</span>
		window.<span class="me1">console</span>.<span class="me1">info</span> <span class="sy0">=</span> <span class="kw3">alert</span><span class="sy0">;</span>
		window.<span class="me1">console</span>.<span class="me1">log</span> <span class="sy0">=</span> <span class="kw3">alert</span><span class="sy0">;</span>
		window.<span class="me1">console</span>.<span class="me1">warn</span> <span class="sy0">=</span> <span class="kw3">alert</span><span class="sy0">;</span>
		window.<span class="me1">console</span>.<span class="me1">error</span> <span class="sy0">=</span> <span class="kw3">alert</span><span class="sy0">;</span>
	<span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div></div>

<p>Whilst you are at it, why not check out some of the other nifty commands available on the Firebug console object at the <a href="http://getfirebug.com/console.html">Get Firebug</a> website.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/referenceerror-console-is-not-defined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AJAX to update the time on a web page from the server</title>
		<link>http://www.codecouch.com/2008/10/using-ajax-to-update-the-time-on-a-web-page/</link>
		<comments>http://www.codecouch.com/2008/10/using-ajax-to-update-the-time-on-a-web-page/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 11:25:19 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=130</guid>
		<description><![CDATA[In an attempt to better explain how you can use AJAX to fetch some data from the server and display it on the web page, I have provided a self contained PHP file.]]></description>
			<content:encoded><![CDATA[<p>Sometimes the easiest way to begin to understand something is through an example. In an attempt to better explain how you can use AJAX to fetch some data from the server and then display it on a web page (without refreshing the page), I constructed the following example PHP page:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="php" style="color: #000000;"><span class="kw2">&lt;?</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">'xhttp'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$counter</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&quot;d M Y h:m:s&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw3">echo</span> <span class="re0">$counter</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw2">?&gt;</span>
<span class="sy0">&lt;</span>html<span class="sy0">&gt;</span>
<span class="sy0">&lt;</span>head<span class="sy0">&gt;</span>
<span class="sy0">&lt;</span>title<span class="sy0">&gt;</span>Test some XHTTP<span class="sy0">&lt;/</span>title<span class="sy0">&gt;</span>
<span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="sy0">&gt;</span>
<span class="kw2">function</span> getHTTPObject<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="kw2">var</span> xmlhttp<span class="sy0">;</span>
	<span class="coMULTI">/*@cc_on
	@if (@_jscript_version &gt;= 5)
		try {
			xmlhttp = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
			} catch (E) {
				xmlhttp = false;
			}
		}
	@else
		xmlhttp = false;
	@end @*/</span>
	<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>xmlhttp <span class="sy0">&amp;&amp;</span> typeof XMLHttpRequest <span class="sy0">!=</span> <span class="st0">'undefined'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		try <span class="br0">&#123;</span>
			xmlhttp <span class="sy0">=</span> <span class="kw2">new</span> XMLHttpRequest<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
		<span class="br0">&#125;</span> catch <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
			xmlhttp <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span>
	<span class="kw1">return</span> xmlhttp<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">function</span> fetchData<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	http <span class="sy0">=</span> getHTTPObject<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	http<span class="sy0">.</span>open<span class="br0">&#40;</span><span class="st0">'get'</span><span class="sy0">,</span> <span class="st0">&quot;&lt;?= $_SERVER['SCRIPT_NAME']; ?&gt;?xhttp=true&quot;</span><span class="sy0">,</span> <span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span>
	http<span class="sy0">.</span>onreadystatechange <span class="sy0">=</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
		<span class="kw1">if</span> <span class="br0">&#40;</span>http <span class="sy0">!=</span> <span class="kw2">null</span> <span class="sy0">&amp;&amp;</span> http<span class="sy0">.</span>readyState <span class="sy0">==</span> <span class="nu0">4</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
			document<span class="sy0">.</span>getElementById<span class="br0">&#40;</span><span class="st0">'displayCounter'</span><span class="br0">&#41;</span><span class="sy0">.</span>innerHTML <span class="sy0">=</span> http<span class="sy0">.</span>responseText<span class="sy0">;</span>
		<span class="br0">&#125;</span>
	<span class="br0">&#125;</span><span class="sy0">;</span>
	http<span class="sy0">.</span>send<span class="br0">&#40;</span><span class="kw2">null</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">function</span> initPage<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	http <span class="sy0">=</span> <span class="kw2">null</span><span class="sy0">;</span>
	pageTimerHandle <span class="sy0">=</span> setInterval<span class="br0">&#40;</span><span class="st0">'fetchData()'</span><span class="sy0">,</span> <span class="nu0">2000</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
window<span class="sy0">.</span>onload <span class="sy0">=</span> initPage<span class="sy0">;</span>
<span class="kw2">&lt;/script&gt;</span>
<span class="sy0">&lt;/</span>head<span class="sy0">&gt;</span>
<span class="sy0">&lt;</span>body<span class="sy0">&gt;</span>
	<span class="sy0">&lt;</span>h1<span class="sy0">&gt;</span>Test page<span class="sy0">&lt;/</span>h1<span class="sy0">&gt;</span>
	<span class="sy0">&lt;</span>p<span class="sy0">&gt;</span>This page is using AJAX to update the <span class="kw3">current</span> <span class="kw3">time</span> every two seconds<span class="sy0">.&lt;/</span>p<span class="sy0">&gt;</span>
	<span class="sy0">&lt;</span>div id<span class="sy0">=</span><span class="st0">&quot;displayCounter&quot;</span><span class="sy0">&gt;&lt;</span>?<span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&quot;d M Y h:m:s&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> ?<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;</span>
<span class="sy0">&lt;/</span>body<span class="sy0">&gt;</span>
<span class="sy0">&lt;/</span>html<span class="sy0">&gt;</span>
<span class="kw2">&lt;?</span> <span class="br0">&#125;</span> <span class="kw2">?&gt;</span></pre></div></div></div>

<p>This block of code is PHP and basically tests to see whether a (GET) parameter (called xhttp) was passed in to the URL:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="php" style="color: #000000;"><span class="kw2">&lt;?</span>
<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">'xhttp'</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
	<span class="re0">$counter</span> <span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&quot;d M Y h:m:s&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
	<span class="kw3">echo</span> <span class="re0">$counter</span><span class="sy0">;</span>
<span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
<span class="kw2">?&gt;</span></pre></div></div></div>

<p>If the xhttp GET parameter was present in the URL, then the server time is sent back, otherwise the whole HTML page is delivered. This allows us to deliver two very different &#8220;pages&#8221; of data back to the browser using the same single PHP file.</p>
<p>The following block of code is used to output the full name of the PHP page being run (the file name) and merely removes the need to specify the file name in the code itself:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="php" style="color: #000000;"><span class="kw2">&lt;?</span><span class="sy0">=</span> <span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">'SCRIPT_NAME'</span><span class="br0">&#93;</span><span class="sy0">;</span> <span class="kw2">?&gt;</span></pre></div></div></div>

<p>The final block of PHP that is prominent in the page is:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="php" style="color: #000000;"><span class="kw2">&lt;?</span><span class="sy0">=</span> <span class="kw3">date</span><span class="br0">&#40;</span><span class="st0">&quot;d M Y h:m:s&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="kw2">?&gt;</span></pre></div></div></div>

<p>This writes out the current date and time to the page (and mimics the same date and time format that will be returned if the PHP file is requested with the GET parameter of xhttp added to it).</p>
<p>Everything else is just HTML and Javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/using-ajax-to-update-the-time-on-a-web-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
