<?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; Browsers</title>
	<atom:link href="http://www.codecouch.com/category/browsers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codecouch.com</link>
	<description>The ramblings of two code monkeys</description>
	<lastBuildDate>Mon, 09 Jan 2012 21:11:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Detecting orientation changes in mobile Safari on iOS, and other supported browsers</title>
		<link>http://www.codecouch.com/2011/11/detecting-orientation-changes-in-mobile-safari-on-ios-and-other-supported-browsers/</link>
		<comments>http://www.codecouch.com/2011/11/detecting-orientation-changes-in-mobile-safari-on-ios-and-other-supported-browsers/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 22:58:24 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=320</guid>
		<description><![CDATA[I&#8217;ve been writing a tool for the iPad recently, and found a need to detect when its orientation had changed (whether from landscape to portrait or vice versa). If I were writing this post years ago, I&#8217;d probably advise that the best way of detecting this change would be to have a timer run a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing a tool for the iPad recently, and found a need to detect when its orientation had changed (whether from landscape to portrait or vice versa).</p>
<p>If I were writing this post years ago, I&#8217;d probably advise that the best way of detecting this change would be to have a timer run a function every half a second or so, with that function detecting the width of the window. I&#8217;m happy to report that times have changed since 2007, when <a href="http://www.evotech.net/blog/2007/07/web-development-for-the-iphone/" title="this blog post">this blog post</a> was written.</p>
<p>These days, things are a lot easier and less clunky: you can listen for the <code>orientationchange</code> event which is fired on iOS devices whenever they change orientation. Having said that, it appears that Safari running on any iPhone doesn&#8217;t fire the 180 degree event and does not rotate the screen when in that orientation (I tested on my 3g, 4, and 4S models). Safari on my iPad fires it for all four positions (0, 90, 180, 270 degrees).</p>
<p>Enough waffle, here is Apple&#8217;s sample code taken from the <a href="http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html" title="Handling Orientation Events">Handling Orientation Events</a> section of their Safari Web Content Guide:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Orientation test&lt;/title&gt;
    <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> updateOrientation<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw2">var</span> displayStr <span class="sy0">=</span> <span class="st0">'Orientation: '</span><span class="sy0">;</span>
&nbsp;
            <span class="kw1">switch</span><span class="br0">&#40;</span>window.<span class="me1">orientation</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw1">case</span> <span class="nu0">0</span><span class="sy0">:</span>
                    displayStr <span class="sy0">+=</span> <span class="st0">'Portrait'</span><span class="sy0">;</span>
                    <span class="kw1">break</span><span class="sy0">;</span>
&nbsp;
                <span class="kw1">case</span> <span class="sy0">-</span><span class="nu0">90</span><span class="sy0">:</span>
                    displayStr <span class="sy0">+=</span> <span class="st0">'Landscape (right, screen turned clockwise)'</span><span class="sy0">;</span>
                    <span class="kw1">break</span><span class="sy0">;</span>
&nbsp;
                <span class="kw1">case</span> <span class="nu0">90</span><span class="sy0">:</span>
                    displayStr <span class="sy0">+=</span> <span class="st0">'Landscape (left, screen turned counterclockwise)'</span><span class="sy0">;</span>
                    <span class="kw1">break</span><span class="sy0">;</span>
&nbsp;
                <span class="kw1">case</span> <span class="nu0">180</span><span class="sy0">:</span>
                    displayStr <span class="sy0">+=</span> <span class="st0">'Portrait (upside-down portrait)'</span><span class="sy0">;</span>
                    <span class="kw1">break</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
&nbsp;
            document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">'output'</span><span class="br0">&#41;</span>.<span class="me1">innerHTML</span> <span class="sy0">=</span> displayStr<span class="sy0">;</span>
        <span class="br0">&#125;</span>
    <span class="sy0">&lt;/</span>script<span class="sy0">&gt;</span>
&lt;/head&gt;
&nbsp;
&lt;body onorientationchange=&quot;updateOrientation();&quot;&gt;
    &lt;div id=&quot;output&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div></div>

<p>There are two things I would change about this code (other than the XHTML 1.0 Strict DOCTYPE, which I&#8217;ve already changed for the much more memorable HTML5 DOCTYPE). The first is the attachment of the event handler as an attribute on the <code>&lt;body&gt;</code> element &#8211; I&#8217;d attach an event listener (it&#8217;s much cleaner IMHO). The second issue both irks and puzzles me: the orientation has to be read from the <code>window</code> object instead of being passed in with the event data. Why is this? I can&#8217;t think of another case where data associated with an event not made available through the event data in some form or other. So why not with this event type?</p>
		<div  class="headingPod headingLevel2 headingLevel2Yellow">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>Reducing the amount of code needed</h2>
						</div>
					</div>
				</div>
			</div>
		</div>
<p>I&#8217;m not a fan of switch statements. Don&#8217;t get me wrong, I&#8217;ll use them when they are appropriate, but I don&#8217;t believe this is such an occasion. All I wanted to do was determine whether my iPad was in landscape or portrait orientation; I really didn&#8217;t care whether the home button was to the left or to the right. After puzzling it over for a few minutes, I realised I could apply the same bitwise AND trick used to determine odd / even numbers (n &#038; 1), using the value 2 instead of 1.</p>
<p>For those of you unfamiliar with bitwise operators, the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators" title="Bitwise Operators page at MDN">Bitwise Operators page at MDN</a> is a good all-round read covering a bit of everything, and <a href="http://bateru.com/news/2011/03/javascript-binary-operations-the-easy-way/" title="JavaScript Binary Operations – the easy way">JavaScript Binary Operations – the easy way</a> is definitely worth a read as well. Anyway, here is my take on how it could be done, followed by an explanation of how it works:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Orientation test&lt;/title&gt;
    <span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="sy0">&gt;</span>
        window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">'orientationchange'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">'output'</span><span class="br0">&#41;</span>.<span class="me1">innerHTML</span> <span class="sy0">=</span> <span class="st0">'Orientation: '</span> <span class="sy0">+</span> <span class="br0">&#91;</span><span class="st0">'Portrait'</span><span class="sy0">,,</span><span class="st0">'Landscape'</span><span class="br0">&#93;</span><span class="br0">&#91;</span>window.<span class="me1">orientation</span> <span class="sy0">&amp;</span> <span class="nu0">2</span><span class="br0">&#93;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span><span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="sy0">&lt;/</span>script<span class="sy0">&gt;</span>
&lt;/head&gt;
&nbsp;
&lt;body&gt;
    &lt;div id=&quot;output&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div></div>

<p>I&#8217;m not going to go into detail about addEventListener in this article, as event handling is already very well documented. All I need to say on the subject is that if you prefer to use the method shown in Apple&#8217;s sample code to attach the event handler from my code, everything should still work correctly.</p>
		<div  class="headingPod headingLevel2 headingLevel2Orange">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>So how does it work?</h2>
						</div>
					</div>
				</div>
			</div>
		</div>
<p>The window object has a read-only property named orientation that holds one of four numbers: 0, -90, 90, or 180. As you might have deduced, these values are the angle of rotation in degrees, from the default upright portrait position.</p>
<p>To better understand how my code works, let&#8217;s take a look at the binary representations of the 5 numbers (I&#8217;m limiting the number of bits to 16 for brevity. In reality, they are operated on as 32-bit numbers):</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="text">Decimal    Binary
&nbsp;
   0       0000000000000000
  90       0000000001011010
 180       0000000010110100
 -90       1111111110100110
   2       0000000000000010</pre></div></div></div>

<p>As with the topic of event handling, the topic of bitwise logic and bitwise operations deserves much more in-depth coverage than I want to go into, so I&#8217;ll keep this brief: the result of a bitwise AND operation between any two bits will be 1 if and <strong>only</strong> if both operands are 1. In all other cases (0/0, 0/1, 1/0), the result will be 0. Here are the results for all for orientation values after the logical AND:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="text">                   Portrait           Landscape            Portrait           Landscape
&nbsp;
(Decimal)                 0                  90                 180                 -90
Binary     0000000000000000    0000000001011010    0000000010110100    1111111110100110
&amp; 2        0000000000000010    0000000000000010    0000000000000010    0000000000000010
Result     0000000000000000    0000000000000010    0000000000000000    0000000000000010
(Decimal)                 0                   2                   0                   2</pre></div></div></div>

<p>Hopefully my very brief explanation makes sense. In a nutshell, the results of the bitwise AND operations are as follows:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="text">  0 &amp; 2 == 0
180 &amp; 2 == 0
 90 &amp; 2 == 2
-90 &amp; 2 == 2</pre></div></div></div>

		<div  class="headingPod headingLevel2 headingLevel2Pink">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>What to do with the result of the bitwise operation</h2>
						</div>
					</div>
				</div>
			</div>
		</div>
<p>If you need to know only whether the device is in landscape mode or not, or portrait mode or not, then you can simply return the result of the bitwise operation and use that in any tests. Remember, 0 equates to false and 2 equates to true, as does 1, or 42, or 109.6, etc. If you really need it as a boolean, the simplest way is to perform two logical NOT operations by using !!, e.g:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Orientation test&lt;/title&gt;
    <span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="sy0">&gt;</span>
        window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">'orientationchange'</span><span class="sy0">,</span> <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
            <span class="co1">// You can test like this (on the values 0 and 2):</span>
&nbsp;
            <span class="kw1">if</span> <span class="br0">&#40;</span>window.<span class="me1">orientation</span> <span class="sy0">&amp;</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="co1">// Do something if in landscape mode</span>
            <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
                <span class="co1">// Do something if in portrait mode</span>
            <span class="br0">&#125;</span>
&nbsp;
&nbsp;
            <span class="co1">// Or, if you really need to have boolean values, then logical NOT the result of the bitwise AND twice</span>
            <span class="co1">// The first NOT converts it to a boolean of the opposite state, the second restores its state</span>
&nbsp;
            <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!!</span><span class="br0">&#40;</span>window.<span class="me1">orientation</span> <span class="sy0">&amp;</span> <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="co1">// Do something if in landscape mode</span>
            <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
                <span class="co1">// Do something if in portrait mode</span>
            <span class="br0">&#125;</span>
&nbsp;
        <span class="br0">&#125;</span><span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="sy0">&lt;/</span>script<span class="sy0">&gt;</span>
&lt;/head&gt;
&nbsp;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div></div>

		<div  class="headingPod headingLevel2 headingLevel2Blue">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>What about the weird array syntax? What do the double commas mean?</h2>
						</div>
					</div>
				</div>
			</div>
		</div>
<p>There&#8217;s nothing special about the double-comma syntax used in the array; it simply means that I&#8217;ve chosen not to define one element of the array (or to put it another way, I&#8217;ve chosen to skip over that position). Therefore, the element at that position in the array will be undefined. The array will still have a length of 3, and it still holds 3 values &#8211; it just so happens that one of these is the value undefined. Element 0 will be the string &#8216;Portrait&#8217;, element 1 will be undefined, and element 2 will be the string &#8216;Landscape&#8217;:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript"><span class="kw2">var</span> arr <span class="sy0">=</span> <span class="br0">&#91;</span><span class="st0">'Portrait'</span><span class="sy0">,,</span><span class="st0">'Landscape'</span><span class="br0">&#93;</span><span class="sy0">;</span>
<span class="kw3">alert</span><span class="br0">&#40;</span>arr<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>         <span class="co1">// 'Portrait'</span>
<span class="kw3">alert</span><span class="br0">&#40;</span>arr<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>         <span class="co1">// undefined</span>
<span class="kw3">alert</span><span class="br0">&#40;</span>arr<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>         <span class="co1">// 'Landscape'</span>
<span class="kw3">alert</span><span class="br0">&#40;</span>arr.<span class="me1">length</span><span class="br0">&#41;</span><span class="sy0">;</span>     <span class="co1">// 3</span></pre></div></div></div>

<p>So, the bitwise AND returns either 0 or 2, and I&#8217;ve got an array with data at elements 0 and 2. If it hasn&#8217;t done so yet, the penny should now be well and truly dropping: the result of the bitwise AND is being used to select one of the two array elements containing data &#8211; data that gives us the orientation.</p>
<p>Here&#8217;s an example of how this might be used in a real situation: The device orientation is added as an attribute to the <code>&lt;body&gt;</code> element, and this is used by the CSS to ensure that content (in this case, an image) is always displayed at the same position on the screen, no matter what the orientation, or where the status bar is. This avoids the problem of having to resize the content &#8211; which can become tricky, depending on the content. Note: this example was designed for the resolution and aspect ratio of the iPad screen. While the image does rotate on an iPhone, it doesn&#8217;t fit nicely. As the code I&#8217;m writing is not designed to be run on an iPhone (the small screen makes it impractical), I haven&#8217;t spent any time getting these examples to look perfect on an iPhone. However, it should be good enough to get the idea across <img src='http://www.codecouch.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<p>There are two things I&#8217;d like to point out about this example: In addition to the orientationchange event, the attribute on the <code>&lt;body&gt;</code> is being updated once the page has loaded so the device doesn&#8217;t have to be rotated to ensure everything is sized correctly. The second point is the issue of the empty CSS rule <code>body[orient="landscape"] {}</code>. On my iPad running iOS 4.3.3, if I do not include this line, the code fails to size the image as expected &#8211; even though the rule contains no styling, and thus should make no difference. Unfortunately, I don&#8217;t have an iPad 2 to test it on. If anyone would like to donate one to me, I&#8217;d be only too happy to accept it <img src='http://www.codecouch.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>If anyone can tell me why this might be happening, or how to fix it without having to frig my code in a manner I thought I&#8217;d seen the last of with IE6 (correction: that was until I found that Safari/iOS will not fire touchstart events on anchors containing semi-opaque PNGs&#8230; Apple must have got the IE6 devs going cheap. <a href="https://devforums.apple.com/thread/132122" title="Read more on the PNG bug">Read more on the PNG bug</a>).</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0&quot; /&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;title&gt;Orientation test&lt;/title&gt;
    <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> updateOrientation<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            document.<span class="me1">body</span>.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">'orient'</span><span class="sy0">,</span> <span class="br0">&#91;</span><span class="st0">'portrait'</span><span class="sy0">,,</span><span class="st0">'landscape'</span><span class="br0">&#93;</span><span class="br0">&#91;</span>window.<span class="me1">orientation</span> <span class="sy0">&amp;</span> <span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            window.<span class="me1">scrollTo</span><span class="br0">&#40;</span><span class="nu0">0</span><span class="sy0">,</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span><span class="sy0">;</span>
        window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">'orientationchange'</span><span class="sy0">,</span> updateOrientation<span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
        window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">'load'</span><span class="sy0">,</span> updateOrientation<span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="sy0">&lt;/</span>script<span class="sy0">&gt;</span>
&nbsp;
    &lt;style type=&quot;text/css&quot;&gt;
        html, body {
            margin: 0px;
            padding: 0px;
        }
        body {
            text-align: center;
        }
        body[orient=&quot;landscape&quot;] {}
        body[orient=&quot;landscape&quot;] img {
            width: 890px;
            height: 690px;
        }
        body[orient=&quot;portrait&quot;] img {
            -webkit-transform: rotate3d(0, 0, 1, -90deg) translate3d(-90px, -22px, 0px);
            width: 890px;
            height: 690px;
        }
    &lt;/style&gt;
&lt;/head&gt;
&nbsp;
&lt;body&gt;
    &lt;img src=&quot;http://oi39.tinypic.com/2l97b41.jpg&quot; /&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></div></div></div>

		<div  class="headingPod headingLevel2 headingLevel2Green">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>A quick note on decimal / binary conversion</h2>
						</div>
					</div>
				</div>
			</div>
		</div>
<p>You can easily convert from decimal to binary in JavaScript by passing 2 as the radix (base) into the toString() method available on every Number instance, and from binary back to decimal by passing 2 as the radix to parseInt. There are some caveats, but for positive integer numbers, you should find these two methods are reliable:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript"><span class="kw3">alert</span><span class="br0">&#40;</span><span class="nu0">6</span>..<span class="me1">toString</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>            <span class="co1">// '110'</span>
<span class="kw3">alert</span><span class="br0">&#40;</span><span class="nu0">42</span>..<span class="me1">toString</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>           <span class="co1">// '101010'</span>
<span class="kw3">alert</span><span class="br0">&#40;</span>parseInt<span class="br0">&#40;</span><span class="st0">'110'</span><span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>        <span class="co1">// 6</span>
<span class="kw3">alert</span><span class="br0">&#40;</span>parseInt<span class="br0">&#40;</span><span class="st0">'101010'</span><span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>     <span class="co1">// 42</span></pre></div></div></div>

<p>I mentioned a few caveats. These are that you will not be able to use the same methods to convert to and from floating point numbers, and negative numbers will need another step or two. As you may have already discovered, the toString representation of -90 in binary is nothing like the number I used:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="text">The -90 I used (16-bit)    1111111110100110
The -90 I used (8-bit)             10100110
-90..toString(2)                   -1011010</pre></div></div></div>

<p>The representation I used is the <a href="http://en.wikipedia.org/wiki/Two's_complement" title="Two's complement page at Wikipedia">two&#8217;s complement</a> of the positive number (90, in this case). Here&#8217;s the quick-and-dirty method I mentioned to give me the correct negative binary representation, which does require specifying a number of bits. For -90/90, an 8-bit number is fine, but I&#8217;ll show the 16-bit version as well:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript"><span class="kw2">var</span> bitCount <span class="sy0">=</span> <span class="nu0">8</span><span class="sy0">;</span>                                                        <span class="co1">// 8 bit version</span>
<span class="kw2">var</span> negativeNum <span class="sy0">=</span> <span class="sy0">-</span><span class="nu0">90</span><span class="sy0">;</span>                                                   <span class="co1">// Negative number to use</span>
<span class="kw2">var</span> combosForBitCount <span class="sy0">=</span> Math.<span class="me1">pow</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="sy0">,</span> bitCount<span class="br0">&#41;</span><span class="sy0">;</span>                           <span class="co1">// 2 ** 8 == 256</span>
<span class="co1">// Here's the conversion to binary and back to decimal</span>
<span class="kw2">var</span> negativeBinary <span class="sy0">=</span> <span class="br0">&#40;</span>combosForBitCount <span class="sy0">+</span> negativeNum<span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span>      <span class="co1">// 10100110</span>
<span class="kw2">var</span> negativeDecimal <span class="sy0">=</span> parseInt<span class="br0">&#40;</span>negativeBinary<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">-</span> combosForBitCount<span class="sy0">;</span>   <span class="co1">// -90</span>
&nbsp;
<span class="kw2">var</span> bitCount <span class="sy0">=</span> <span class="nu0">16</span><span class="sy0">;</span>                                                       <span class="co1">// 16 bit version</span>
<span class="kw2">var</span> negativeNum <span class="sy0">=</span> <span class="sy0">-</span><span class="nu0">90</span><span class="sy0">;</span>                                                   <span class="co1">// Negative number to use</span>
<span class="kw2">var</span> combosForBitCount <span class="sy0">=</span> Math.<span class="me1">pow</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="sy0">,</span> bitCount<span class="br0">&#41;</span><span class="sy0">;</span>                           <span class="co1">// 2 ** 16 == 65536</span>
<span class="co1">// Here's the conversion to binary and back to decimal</span>
<span class="kw2">var</span> negativeBinary <span class="sy0">=</span> <span class="br0">&#40;</span>combosForBitCount <span class="sy0">+</span> negativeNum<span class="br0">&#41;</span>.<span class="me1">toString</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span>      <span class="co1">// 1111111110100110</span>
<span class="kw2">var</span> negativeDecimal <span class="sy0">=</span> parseInt<span class="br0">&#40;</span>negativeBinary<span class="sy0">,</span> <span class="nu0">2</span><span class="br0">&#41;</span> <span class="sy0">-</span> combosForBitCount<span class="sy0">;</span>   <span class="co1">// -90</span></pre></div></div></div>

<p>It&#8217;s probably worth mentioning that there are multiple ways of converting negative binary numbers, and the method I&#8217;ve given above shouldn&#8217;t be used without ensuring that it is providing valid results. I really only included it so you could see how I obtained the binary value for -90. If you haven&#8217;t lost the will to live just yet, I&#8217;d read through the <a href="http://celtickane.com/projects/computer-science-primer/binary-numbers/" title="Binary Numbers page at Celtic Kane Online">Binary Numbers page at Celtic Kane Online</a> and the <a href="http://en.wikipedia.org/wiki/Signed_number_representations" title="Wikipedia article on Signed number representations">Wikipedia article on Signed number representations</a>.</p>
<p>The floating point issue is easy to understand: parseInt can&#8217;t be used to convert a floating point number (the clue is in its name), and parseFloat doesn&#8217;t take a radix. Converting to and from floating point binary numbers, while not overly tricky, isn&#8217;t something I will go into here. I can recommend <a href="http://www.amazon.co.uk/gp/product/0070379904/ref=as_li_tf_tl?ie=UTF8&#038;tag=codcou-21&#038;linkCode=as2&#038;camp=1634&#038;creative=6738&#038;creativeASIN=0070379904">Essential Computer Mathematics by Seymour Lipschutz (Schaum&#8217;s Outline Series)</a><img src="http://www.assoc-amazon.co.uk/e/ir?t=codcou-21&#038;l=as2&#038;o=2&#038;a=0070379904" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> as a fantastic all-round read (I still refer to my 1982 copy today, and have even taught the occasional class with the book as my only aid). 40+ million students can&#8217;t be wrong!</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Detecting+orientation+changes+in+mobile+Safari+on+iOS%2C+and+other+supported+browsers+http%3A%2F%2Fis.gd%2Fm71c8i" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2011/11/detecting-orientation-changes-in-mobile-safari-on-ios-and-other-supported-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spell checking in Firefox</title>
		<link>http://www.codecouch.com/2008/12/spell-checking-in-firefox/</link>
		<comments>http://www.codecouch.com/2008/12/spell-checking-in-firefox/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 21:07:05 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[spell]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=233</guid>
		<description><![CDATA[Want to know how to spell check an entire web page in Firefox? Or how to add spell-checking to fields that do not have it by default? Read on for more.]]></description>
			<content:encoded><![CDATA[<p>A handy tip I came across the other day was how to spell-check an entire web page using Firefox &#8211; not just textarea elements.</p>
<p>You basically put the page into design mode &#8211; so the content becomes editable. Enter this in the URL bar:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="javascript">javascript<span class="sy0">:</span><span class="kw1">void</span><span class="br0">&#40;</span>document.<span class="me1">designMode</span><span class="sy0">=</span><span class="st0">'on'</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div></div>

<p>You can also add spell checking to fields which do not have it by default (e.g. single-line input elements) by adding a &#8220;spellcheck&#8221; attribute set to &#8220;true&#8221;, e.g.:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">size</span><span class="sy0">=</span><span class="st0">&quot;50&quot;</span> spellcheck<span class="sy0">=</span><span class="st0">&quot;true&quot;</span>&gt;</span></pre></div></div></div>

<p>See <a href="https://developer.mozilla.org/en/Controlling_spell_checking_in_HTML_forms">https://developer.mozilla.org/en/Controlling_spell_checking_in_HTML_forms</a> for more information.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Spell+checking+in+Firefox+http%3A%2F%2Fis.gd%2FBprV03" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/12/spell-checking-in-firefox/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>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Problems+tabbing+through+checkboxes+and+radios+in+MacOSX+Safari+http%3A%2F%2Fis.gd%2FprUa6U" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></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="headingPod headingLevel2 headingLevel2Blue">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>The problem</h2>
						</div>
					</div>
				</div>
			</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">&lt;style type<span class="sy0">=</span><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="co2">images/alphaTransparent.png</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="sy0">=</span><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>.AlphaImageLoader<span class="br0">&#40;</span>enabled<span class="sy0">=</span>true<span class="sy0">,</span>sizingMethod<span class="sy0">=</span><span class="kw2">crop</span><span class="sy0">,</span>src<span class="sy0">=</span>images/alphaTransparent.png<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">...
<span class="sc2">&lt;<span class="kw2">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>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">span</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;child&quot;</span>&gt;</span>Lorem <span class="sc2">&lt;<span class="kw2">a</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;http://www.codecouch.com&quot;</span>&gt;</span>ipsum<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">a</span>&gt;</span> dolor.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">span</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</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="headingPod headingLevel2 headingLevel2Green">
			<div class="img">
				<div class="verticalCentreOuter">
					<div class="verticalCentreMiddle">
						<div class="verticalCentreInner">
							<h2>The solution</h2>
						</div>
					</div>
				</div>
			</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">&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="sy0">=</span><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>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Problems+with+anchors+and+alpha+transparency+filters+in+IE6+http%3A%2F%2Fis.gd%2FpJHlLw" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></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>Fixing a disappearing caret in Firefox</title>
		<link>http://www.codecouch.com/2008/10/fixing-a-disappearing-caret-in-firefox/</link>
		<comments>http://www.codecouch.com/2008/10/fixing-a-disappearing-caret-in-firefox/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 12:45:53 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=178</guid>
		<description><![CDATA[The disappearing caret issue in Firefox is very annoying. There are many variations of this bug, most with fixes or workarounds. This fix is for the case where input elements on top of a fixed element do not have a caret.]]></description>
			<content:encoded><![CDATA[<p>There are many issues with Firefox hiding the caret (cursor) in text fields which have focus. There are various fixes, depending on the specifics of your issue, which mostly involve adding a style of &#8220;overflow:auto&#8221; to the input or container in question.</p>
<p>There is one case that doesn&#8217;t appear to have a fix, other than upgrading to Firefox 3: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=230701">The cursor (caret) in a text input turns invisible when it is over a fixed element</a>. I&#8217;ve known about this problem for a while, and have tried many solutions that fixed similar issues, but they never seemed to work for this specific one.</p>
<p>I&#8217;ve found a solution that works, but it has 2 drawbacks:</p>
<ol>
<li>It requires JavaScript to work</li>
<li>It causes rendering errors on the fixed element when scrolling (almost as if the fixed element is scrolling as well)</li>
</ol>
<p>Using the test harness below, you can see the problem and the fix. I&#8217;ve included my test background image after the code, to make the rendering problem very obvious.</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc0">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;</span>
<span class="sc2">&lt;<span class="kw2">html</span> xmlns<span class="sy0">=</span><span class="st0">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span class="kw3">dir</span><span class="sy0">=</span><span class="st0">&quot;ltr&quot;</span> <span class="kw3">lang</span><span class="sy0">=</span><span class="st0">&quot;en-US&quot;</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">head</span> <span class="kw3">profile</span><span class="sy0">=</span><span class="st0">&quot;http://gmpg.org/xfn/11&quot;</span>&gt;</span>
	<span class="sc2">&lt;<span class="kw2">meta</span> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;content-type&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;text/html; charset=UTF-8&quot;</span> <span class="sy0">/</span>&gt;</span>
	<span class="sc2">&lt;<span class="kw2">meta</span> <span class="kw3">http-equiv</span><span class="sy0">=</span><span class="st0">&quot;content-language&quot;</span> <span class="kw3">content</span><span class="sy0">=</span><span class="st0">&quot;en&quot;</span> <span class="sy0">/</span>&gt;</span>
	<span class="sc2">&lt;<span class="kw2">title</span>&gt;</span>Disappearing caret bug - workaround<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">title</span>&gt;</span>
&nbsp;
	<span class="sc2">&lt;<span class="kw2">style</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span>&gt;</span>
		#fixedDiv {
			width: 100%;
			height: 100%;
			top: 0px;
			left: 0px;
			background: url(caretBugBg.gif);
			position: fixed;
		}
&nbsp;
		#contentDiv {
			position: relative;
		}
	<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">style</span>&gt;</span>
&nbsp;
	<span class="sc2">&lt;<span class="kw2">script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
		function fixCaretBug() {
			document.getElementById('fixedDiv').style.zIndex = -1;
			setTimeout(fixCaretBugPartTwo, 0);
		}
&nbsp;
		function fixCaretBugPartTwo() {
			document.getElementById('fixedDiv').style.zIndex = 0;
		}
	<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">script</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">head</span>&gt;</span>
&nbsp;
<span class="sc2">&lt;<span class="kw2">body</span>&gt;</span>
	<span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;fixedDiv&quot;</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
&nbsp;
	<span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;contentDiv&quot;</span>&gt;</span>
		<span class="sc2">&lt;<span class="kw2">form</span>&gt;</span>
			<span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span> <span class="kw3">size</span><span class="sy0">=</span><span class="st0">&quot;50&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;You cannot see the caret in this text input field...&quot;</span> <span class="sy0">/</span>&gt;</span>
			<span class="sc2">&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;</span>
			<span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;button&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Click me to fix that!&quot;</span> <span class="kw3">onclick</span><span class="sy0">=</span><span class="st0">&quot;fixCaretBug();&quot;</span> <span class="sy0">/</span>&gt;</span>
		<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">form</span>&gt;</span>
&nbsp;
		<span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>This text...<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span>
		<span class="sc2">&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;</span>
&nbsp;
		<span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>is used...<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span>
		<span class="sc2">&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;</span>
&nbsp;
		<span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>to produce a vertical scrollbar.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span>
		<span class="sc2">&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;</span>
&nbsp;
		<span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>If you cannot see a vertical scrollbar,<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span>
		<span class="sc2">&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;</span>
&nbsp;
		<span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>reduce the size of your browser window.<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span>
		<span class="sc2">&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;&lt;<span class="kw2">br</span> <span class="sy0">/</span>&gt;</span>
	<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
&nbsp;
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">body</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">html</span>&gt;</span></pre></div></div></div>

<p>There is a small flicker when the fix is enabled, although this could potentially be fixed by hooking into the DOMContentLoaded event and running the fix before the background image is loaded.</p>
<div id="attachment_182" class="wp-caption" style="width:300px;"><div style="font-size:0px;"><a href="http://www.codecouch.com/wp-content/uploads/2008/10/caretbugbg.gif"><img src="http://www.codecouch.com/wp-content/uploads/2008/10/caretbugbg-300x225.gif" alt="A grey rectangle with a black cross on top of it" title="Disappearing caret bug - workaround demo background image" width="300" height="225" class="size-medium wp-image-182" /></a></div><div class="markupPod ">
My test background image</div>
</div>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=Fixing+a+disappearing+caret+in+Firefox+http%3A%2F%2Fis.gd%2F3Pk9fj" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2008/10/fixing-a-disappearing-caret-in-firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do I display alpha transparent PNGs across all browsers?</title>
		<link>http://www.codecouch.com/2007/05/how-do-i-display-alpha-transparent-pngs-across-all-browsers/</link>
		<comments>http://www.codecouch.com/2007/05/how-do-i-display-alpha-transparent-pngs-across-all-browsers/#comments</comments>
		<pubDate>Sat, 05 May 2007 09:40:05 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Graphical]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=104</guid>
		<description><![CDATA[Find out how you can use alpha transparency successfully across all browsers - and specifically IE 6 for Windows.]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> This article was written when developers had to whip IE6 into shape. If you&#8217;re still coding for IE6, perhaps retraining as plumber might be more advisable? <img src='http://www.codecouch.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Many web developers have shunned the <acronym title="Portable Network Graphics">PNG</acronym> image format in the past. For some this has been because of a perceived lack of support for alpha transparency (described formally as <a title="Wikipedia entry" href="http://en.wikipedia.org/wiki/Alpha_compositing">alpha compositing</a>) in Internet Explorer. Here are some directions on how you can use alpha transparency successfully across all browsers &#8211; and specifically IE 6 for Windows.</p>
<p>The examples below rely on the following CSS code (described below):</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css">&lt;style type<span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
  <span class="re0">#demo1</span> <span class="br0">&#123;</span>
    <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">250px</span><span class="sy0">;</span>
    <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">100px</span><span class="sy0">;</span>
    <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">images/logo.png</span><span class="br0">&#41;</span> <span class="kw2">transparent</span> <span class="nu0">0</span> <span class="nu0">0</span> <span class="kw2">no-repeat</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span>
&lt;!––<span class="br0">&#91;</span>if lt IE <span class="nu0">7</span><span class="br0">&#93;</span><span class="sy0">&gt;</span>
&lt;style type<span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
  <span class="re0">#demo1</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<span class="sy0">=</span>true<span class="sy0">,</span>sizingMethod<span class="sy0">=</span>scale<span class="sy0">,</span>src<span class="sy0">=</span>/images/logo.png<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>

<p>The first block of CSS sets a background image on an element with the id “demo1″ (typically a div, span or img) for all browsers. This works fine for everything else, but doesn’t work with IE prior to version 7.</p>
<p>The second block targets just these “broken” browsers through use of a <a href="http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp">conditional comment</a>. This second block uses the filter property to set up a proper alpha transparent version of the png. Read more about this here at the <a href="http://msdn2.microsoft.com/en-us/library/ms532969.aspx">MSDN site</a>.</p>
<p>In the following example the CSS above would show the logo.png with alpha transparency as the background to a div:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;demo1&quot;</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span></pre></div></div></div>

<p>This next example shows that you can display a png with alpha transparency by targetting a transparent image:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">img</span> <span class="kw3">src</span><span class="sy0">=</span><span class="st0">&quot;transparent.gif&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;demo1&quot;</span> <span class="kw3">alt</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">/</span>&gt;</span></pre></div></div></div>

<p>There are plenty of variations of this technique. All the examples above are considered “standards friendly”. This final example shows the same CSS simplified (but not passing validation):</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="css">&lt;style type<span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span><span class="sy0">&gt;</span>
  <span class="re0">#demo1</span> <span class="br0">&#123;</span>
    <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">250px</span><span class="sy0">;</span>
    <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">100px</span><span class="sy0">;</span>
    <span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="co2">images/logo.png</span><span class="br0">&#41;</span> <span class="kw2">transparent</span> <span class="nu0">0</span> <span class="nu0">0</span> <span class="kw2">no-repeat</span><span class="sy0">;</span>
    _background-image<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<span class="sy0">=</span>true<span class="sy0">,</span>sizingMethod<span class="sy0">=</span>scale<span class="sy0">,</span>src<span class="sy0">=</span>/images/logo.png<span class="br0">&#41;</span><span class="sy0">;</span>
  <span class="br0">&#125;</span>
&lt;/style<span class="sy0">&gt;</span></pre></div></div></div>

<p>If you are putting the CSS above into an external stylesheet, then be aware that the path to the logo.png when used as the background image is relative to the CSS file, but the path to logo.png when used in the filter is relative to the enclosing HTML file. This can cause some confusion.</p>
<p>On a related note… you should always <a href="http://www.codecouch.com/2007/06/make-your-alpha-transparent-pngs-32-bit/">ensure your alpha transparent PNGs are 32-bit</a> to ensure that they always display the same colour across all browsers (specifically Firefox and IE displayed a 24-bit alpha transparent PNG differently using the technique described here &#8211; changing it to 32-bit confirmed this was the case).</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+do+I+display+alpha+transparent+PNGs+across+all+browsers%3F+http%3A%2F%2Fis.gd%2FCoHeSq" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2007/05/how-do-i-display-alpha-transparent-pngs-across-all-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to target specific IE browsers using just HTML?</title>
		<link>http://www.codecouch.com/2007/04/how-to-target-specific-ie-browsers-using-just-html/</link>
		<comments>http://www.codecouch.com/2007/04/how-to-target-specific-ie-browsers-using-just-html/#comments</comments>
		<pubDate>Wed, 18 Apr 2007 10:08:01 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[HTML/XHTML]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.codecouch.com/?p=110</guid>
		<description><![CDATA[Conditional comments are totally valid markup (for HTML as well as XHTML doctypes) that cause IE browsers running in Windows to parse the contents of the commented markup.]]></description>
			<content:encoded><![CDATA[<p>Many people were introduced to <a href="http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp">conditional comments</a> with the introduction of IE7 and their grass-roots <a href="http://blogs.msdn.com/ie/archive/2005/10/12/480242.aspx">call to action</a> to stop using “CSS Hacks” to target specific IE browser versions.</p>
<p>Conditional comments are totally valid markup (for HTML as well as XHTML doctypes) that cause IE browsers running in Windows (the old Mac versions of IE ignored them completely) to parse the contents of the commented markup.</p>
<p>The following code shows how a conditional comment can be used to match “all versions of IE less than version 7″ and include an extra css file and an extra div in the content of the page:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">html</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">head</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">link</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;default.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;!––<span class="br0">&#91;</span>if lt IE <span class="nu0">7</span><span class="br0">&#93;</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">link</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;iexplore.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>––&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">head</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">body</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">h1</span>&gt;</span>Testing<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">h1</span>&gt;</span>
<span class="sc2">&lt;!––<span class="br0">&#91;</span>if lt IE <span class="nu0">7</span><span class="br0">&#93;</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">div</span>&gt;</span>I’m an old IE running in Windows<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
<span class="sc2">&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>––&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">body</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">html</span>&gt;</span></pre></div></div></div>

<p>Because of the start HTML comment code (<code>&lt;!--</code>), everything until the close HTML comment code (<code>--&gt;</code>) is treated as a comment for non matching IE Windows browsers.</p>
<p>The code that is actually rendered by the browser is different when viewed in IE Windows browsers older than IE7 and any other browser:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">html</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">head</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">link</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;default.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="sy0">/</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">link</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;iexplore.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">head</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">body</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">h1</span>&gt;</span>Testing<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">h1</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">div</span>&gt;</span>I'm an old IE running in Windows<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">body</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">html</span>&gt;</span></pre></div></div></div>

<p>This is the code that is rendered in other browsers:</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">html</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">head</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">link</span> <span class="kw3">href</span><span class="sy0">=</span><span class="st0">&quot;default.css&quot;</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/css&quot;</span> <span class="kw3">rel</span><span class="sy0">=</span><span class="st0">&quot;stylesheet&quot;</span> <span class="sy0">/</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">head</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">body</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">h1</span>&gt;</span>Testing<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">h1</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">body</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">html</span>&gt;</span></pre></div></div></div>

<p>You might choose to use this to set some variables on the page for javascript to use &#8211; without having to worry about user agent detection issues and spoofing browsers (remember that this will not work for the old IE Mac browsers &#8211; only Windows):</p>

<div class="wp_syntax_outer"><div class="wp_syntax"><div class="wp_syntax_inner"><pre class="html4strict"><span class="sc2">&lt;<span class="kw2">script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
  var isIE=isIE5=isIE6=isIE7=false;
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">script</span>&gt;</span>
<span class="sc2">&lt;!––<span class="br0">&#91;</span>if IE<span class="br0">&#93;</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
    isIE=true;
  <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">script</span>&gt;</span>
<span class="sc2">&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>––&gt;</span>
<span class="sc2">&lt;!––<span class="br0">&#91;</span>if IE <span class="nu0">7</span><span class="br0">&#93;</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
    isIE7=true;
  <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">script</span>&gt;</span>
<span class="sc2">&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>––&gt;</span>
<span class="sc2">&lt;!––<span class="br0">&#91;</span>if IE <span class="nu0">6</span><span class="br0">&#93;</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
    isIE6=true;
  <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">script</span>&gt;</span>
<span class="sc2">&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>––&gt;</span>
<span class="sc2">&lt;!––<span class="br0">&#91;</span>if IE <span class="nu0">5</span><span class="br0">&#93;</span>&gt;</span>
  <span class="sc2">&lt;<span class="kw2">script</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span>&gt;</span>
    isIE5=true;
  <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">script</span>&gt;</span>
<span class="sc2">&lt;!<span class="br0">&#91;</span>endif<span class="br0">&#93;</span>––&gt;</span></pre></div></div></div>

<p>Be sure to check out the difference between <b>down-level hidden</b> (which is what I have used all the examples in this FAQ) and <b>down-level revealed</b> at the <a href="http://msdn.microsoft.com/workshop/author/dhtml/overview/ccomment_ovw.asp">MSDN conditional comments</a> page.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target="_blank" rel="nofollow" class="tt" href="http://twitter.com/intent/tweet?text=How+to+target+specific+IE+browsers+using+just+HTML%3F+http%3A%2F%2Fis.gd%2Fb3tJaD" title="Post to Twitter"><img class="nothumb" src="http://www.codecouch.com/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter-big4.png" alt="Post to Twitter" /></a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.codecouch.com/2007/04/how-to-target-specific-ie-browsers-using-just-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

