<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3" -->
<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/"
	>

<channel>
	<title>Technology Blog</title>
	<link>http://tech.gpuri.com</link>
	<description>technology is a seductress</description>
	<pubDate>Sun, 14 Mar 2010 01:04:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
	<language>en</language>
			<item>
		<title>CSS and JavaScript Best Practices</title>
		<link>http://tech.gpuri.com/51/css-and-javascript-best-practices/</link>
		<comments>http://tech.gpuri.com/51/css-and-javascript-best-practices/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 23:55:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Browser]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/51/css-and-javascript-best-practices/</guid>
		<description><![CDATA[

  

CSS Best Practices
 
DOCTYPE
Browsers can render your HTML code in many different ways. The DOCTYPE of an HTML document tells the browser how you want it to interpret and display your code. The most common DOCTYPES are HTML 4.01 Strict, HTML 4.01 Transitional, XHTML 1.0 Strict and XHTML 1.0 Transitional.
XHTML is a stricter and [...]]]></description>
			<content:encoded><![CDATA[<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<link href="file:///C:%5CDOCUME%7E1%5Cgpuri01%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml" rel="File-List" /><o:smarttagtype namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"></o:smarttagtype><!--[if gte mso 9]><xml>  <w:WordDocument>   <w:View>Normal</w:View>   <w:Zoom>0</w:Zoom>   <w:PunctuationKerning/>   <w:ValidateAgainstSchemas/>   <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>   <w:IgnoreMixedContent>false</w:IgnoreMixedContent>   <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>   <w:Compatibility>    <w:BreakWrappedTables/>    <w:SnapToGridInCell/>    <w:WrapTextWithPunct/>    <w:UseAsianBreakRules/>    <w:DontGrowAutofit/>   </w:Compatibility>   <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>  </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml>  <w:LatentStyles DefLockedState="false" LatentStyleCount="156">  </w:LatentStyles> </xml><![endif]--><!--[if !mso]><object  classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object><br />
<style> st1\:*{behavior:url(#ieooui) } </style>
<p> <![endif]--><br />
<style> <!--  /* Font Definitions */  @font-face 	{font-family:Wingdings; 	panose-1:5 0 0 0 0 0 0 0 0 0; 	mso-font-charset:2; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:0 268435456 0 0 -2147483648 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} h2 	{mso-style-next:Normal; 	margin-top:12.0pt; 	margin-right:0in; 	margin-bottom:3.0pt; 	margin-left:0in; 	mso-pagination:widow-orphan; 	page-break-after:avoid; 	mso-outline-level:2; 	font-size:14.0pt; 	font-family:Arial; 	font-weight:bold; 	font-style:italic;} h3 	{mso-style-next:Normal; 	margin-top:12.0pt; 	margin-right:0in; 	margin-bottom:3.0pt; 	margin-left:0in; 	mso-pagination:widow-orphan; 	page-break-after:avoid; 	mso-outline-level:3; 	font-size:13.0pt; 	font-family:Arial; 	font-weight:bold;} h4 	{mso-style-next:Normal; 	margin-top:12.0pt; 	margin-right:0in; 	margin-bottom:3.0pt; 	margin-left:0in; 	mso-pagination:widow-orphan; 	page-break-after:avoid; 	mso-outline-level:4; 	font-size:14.0pt; 	font-family:"Times New Roman"; 	font-weight:bold;} p.MsoMessageHeader, li.MsoMessageHeader, div.MsoMessageHeader 	{margin-top:0in; 	margin-right:0in; 	margin-bottom:0in; 	margin-left:.75in; 	margin-bottom:.0001pt; 	text-indent:-.75in; 	mso-pagination:widow-orphan; 	background:#CCCCCC; 	mso-shading:windowtext; 	mso-pattern:gray-20 auto; 	border:none; 	mso-border-alt:solid windowtext .75pt; 	padding:0in; 	mso-padding-alt:1.0pt 1.0pt 1.0pt 1.0pt; 	font-size:12.0pt; 	font-family:Arial; 	mso-fareast-font-family:"Times New Roman";} a:link, span.MsoHyperlink 	{color:blue; 	text-decoration:underline; 	text-underline:single;} a:visited, span.MsoHyperlinkFollowed 	{color:purple; 	text-decoration:underline; 	text-underline:single;} p 	{mso-margin-top-alt:auto; 	margin-right:0in; 	mso-margin-bottom-alt:auto; 	margin-left:0in; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman"; 	mso-fareast-font-family:"Times New Roman";} code 	{font-family:"Courier New"; 	mso-ascii-font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman"; 	mso-hansi-font-family:"Courier New"; 	mso-bidi-font-family:"Courier New";} pre 	{margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	tab-stops:45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; 	font-size:10.0pt; 	font-family:"Courier New"; 	mso-fareast-font-family:"Times New Roman";} span.comment 	{mso-style-name:comment;} span.keyword 	{mso-style-name:keyword;} span.sc3 	{mso-style-name:sc3;} span.re1 	{mso-style-name:re1;} span.re0 	{mso-style-name:re0;} span.st0 	{mso-style-name:st0;} span.re2 	{mso-style-name:re2;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.25in 1.0in 1.25in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}  /* List Definitions */  @list l0 	{mso-list-id:217325846; 	mso-list-type:hybrid; 	mso-list-template-ids:-180967654 67698693 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l0:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	font-family:Wingdings;} @list l1 	{mso-list-id:389813928; 	mso-list-type:hybrid; 	mso-list-template-ids:-1131615572 67698693 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l1:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	font-family:Wingdings;} @list l2 	{mso-list-id:638537446; 	mso-list-type:hybrid; 	mso-list-template-ids:334366486 67698693 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l2:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	font-family:Wingdings;} @list l3 	{mso-list-id:771633117; 	mso-list-template-ids:-112810784;} @list l3:level1 	{mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in;} @list l4 	{mso-list-id:1742673099; 	mso-list-template-ids:-1030554058;} @list l4:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	mso-ansi-font-size:10.0pt; 	font-family:Symbol;} ol 	{margin-bottom:0in;} ul 	{margin-bottom:0in;} --> </style>
<p><!--[if gte mso 10]></p>
<style>  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:10.0pt; 	font-family:"Times New Roman"; 	mso-ansi-language:#0400; 	mso-fareast-language:#0400; 	mso-bidi-language:#0400;} </style>
<p> <![endif]--></p>
<h2><a title="_Toc256266234" name="_Toc256266234"></a>CSS Best Practices</h2>
<p class="MsoNormal"><o:p> </o:p></p>
<h3><a title="_Toc256266235" name="_Toc256266235"></a>DOCTYPE</h3>
<p>Browsers can render your HTML code in many different ways. The DOCTYPE of an HTML document tells the browser how you want it to interpret and display your code. The most common DOCTYPES are HTML 4.01 Strict, HTML 4.01 Transitional, XHTML 1.0 Strict and XHTML 1.0 Transitional.</p>
<p>XHTML is a stricter and cleaner version of HTML.</p>
<h4>Differences between HTML and XHTML:</h4>
<p class="MsoNormal"><o:p> </o:p></p>
<ul style="margin-top: 0in" type="square">
<li class="MsoNormal"><strong>Stricter      adherence to the HTML specification.</strong><br />
Many browsers are very lax in how they interpret HTML. This leads to incongruities      in how the pages are displayed, and XHTML doesn&#8217;t allow that.</li>
</ul>
<p class="MsoNormal" style="margin-left: 0.25in"><o:p> </o:p></p>
<ul style="margin-top: 0in" type="square">
<li class="MsoNormal"><strong>Write      well formed documents.</strong><br />
What this generally means is avoiding overlapping elements. The following nested      code is acceptable:</li>
</ul>
<p class="MsoNormal" style="margin-left: 0.5in"><code><span style="font-size: 10pt">&lt;p&gt;Paragraph &lt;em&gt;emphasized&lt;/em&gt;&lt;/p&gt; </span></code>because the &lt;em&gt; tag is opened and closed within the &lt;p&gt; tag.</p>
<p class="MsoNormal" style="margin-left: 0.25in; text-indent: 0.25in">However, this is not allowed:</p>
<p class="MsoNormal" style="margin-left: 0.5in"><code><span style="font-size: 10pt">&lt;p&gt;Paragraph &lt;em&gt;emphasized&lt;/p&gt;&lt;/em&gt; </span></code>because the &lt;em&gt; tag overlaps the &lt;p&gt; tag.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<ul style="margin-top: 0in" type="square">
<li class="MsoNormal"><strong>Write      tags and attributes in lowercase.</strong><br />
XHTML is a case-sensitive markup language, so <code><span style="font-size: 10pt">&lt;LI&gt; and &lt;li&gt; </span></code>are      potentially two different tags.</li>
</ul>
<p class="MsoNormal" style="margin-left: 0.25in"><o:p> </o:p></p>
<ul style="margin-top: 0in" type="square">
<li class="MsoNormal"><strong>End      tags are required.</strong><br />
In HTML, some tags which actually contain elements do not require the end      tag. The most common of these is the <code><span style="font-size: 10pt">&lt;p&gt;      </span></code>tag. XHTML requires that the <code><span style="font-size: 10pt">&lt;/p&gt; </span></code>tag be used. For singleton tags, such as <code><span style="font-size: 10pt">&lt;br&gt; </span></code>you should include a      trailing slash in the tag itself, e.g. <span> </span><code><span style="font-size: 10pt">&lt;br      /&gt; </span></code>to get a line break.</li>
</ul>
<p class="MsoNormal" style="margin-left: 0.25in"><o:p> </o:p></p>
<ul style="margin-top: 0in" type="square">
<li class="MsoNormal"><strong>Attributes      must be quoted and include values.</strong><br />
What this means is that non-quoted attributes such as <code><span style="font-size: 10pt">&lt;table border=3&gt;</span></code></li>
</ul>
<p class="MsoNormal" style="margin-left: 0.5in">are invalid. And attributes which used to stand alone, must now be written as name=&#8221;value&#8221; pairs. For example <code><span style="font-size: 10pt">&lt;hr noshade=&#8221;noshade&#8221; /&gt; </span></code>adds the noshade attribute to the &lt;hr/&gt; tag.</p>
<p style="margin-left: 0.5in; text-indent: -0.25in"><!--[if !supportLists]--><span style="font-family: Wingdings"><span>§<span style="font: 7pt 'Times New Roman'">         </span></span></span><!--[endif]-->The root element of an XHTML document must be <code><span style="font-size: 10pt">html</span></code>, and must contain an <code><span style="font-size: 10pt">xmlns</span></code> attribute to associate it with the XHTML namespace. The namespace URI for XHTML is <code><span style="font-size: 10pt">http://www.w3.org/1999/xhtml</span></code>. The example tag below additionally features an <code><span style="font-size: 10pt">xml:lang</span></code> attribute to identify the document with a natural language:</p>
<pre style="margin-left: 0.25in"><span class="re1"><span>   </span>&lt;html</span><span class="sc3"> </span><span class="re0">xmlns</span><span class="sc3">=</span><span class="st0">&#8220;http://www.w3.org/1999/xhtml&#8221;</span><span class="sc3"> </span><span class="re0">xml:lang</span><span class="sc3">=</span><span class="st0">&#8220;en&#8221;</span><span class="re2">&gt;</span></pre>
<p class="MsoNormal" style="margin-left: 0.5in"><o:p> </o:p></p>
<p>Use XHTML 1.0 Strict DOCTYPE to clean markup, free of presentational clutter. There are two good reasons why we should be headed toward XHTML:</p>
<ul type="square">
<li class="MsoNormal">HTML won’t be updated      anymore. It has absorbed some XML features and turned into XHTML. HTML is      dead. For that matter, XHTML will be dead when it moves totally to XML.</li>
<li class="MsoNormal">XHTML gives your code the      ability to be read on XML devices so you can, again, keep current with the      trend of making Web pages available on more devices/arenas than just the      local computer or Internet.</li>
</ul>
<p>XHTML 1.0 <strong><span style="font-weight: normal">strict DOCTYPE declaration</span></strong><strong>:</strong></p>
<p>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Strict//EN&#8221;<br />
&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#8221;&gt;</p>
<p>Using a DOCTYPE is a necessity for validating one’s XHTML, which is a great way to keep your code compliant, to quickly find any coding mistakes you may have made, and to perhaps help meet any standards requirements.</p>
<h3><a title="_Toc256266236" name="_Toc256266236"></a>External Style Sheets</h3>
<p>The STYLE tag should be avoided wherever possible. Style sheets should be externally linked and only imported when a special requirement needs to be met, such as Mac/IE consideration.</p>
<p>For larger projects, it is usually easiest to break the style sheets up either by area or code group.</p>
<h3><a title="_Toc256266237" name="_Toc256266237"></a>TABLE Tags for Layout?</h3>
<p>TABLEs are quirky in the various browsers. They are not “appropriate” to use for layout, they don’t seem to mix well with CSS, and they pose accessibility issues. Use &lt;div&gt; tag for instead.</p>
<h3><a title="_Toc256266238" name="_Toc256266238"></a>Pixels, Percentages, or <st1:place w:st="on"><span>EMs</span></st1:place><span> for Font Sizes?</span></h3>
<p>There are other choices for the font-size unit, but pixels (PX) seem to be the most used. They are the most reliable, simply because they cause the least grief during development. However, it is not the most accessible, since IE will not resize the PX unit.</p>
<p>If your project does require relative font-sizes, EM is the best choice. You can combat some of EM’s complexities by preparing the CSS a little. For example, Set the BODY font-size to 16px and then used EM as a measurement throughout to create a design where the majority of elements could be resized according to font size of the user.</p>
<p>1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then &#8216;2em&#8217; is 24 pt. The &#8216;em&#8217; is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses</p>
<h3><a title="_Toc256266239" name="_Toc256266239"></a>Float or Position your Advanced CSS Layout?</h3>
<p>CSS-based layouts usually require either FLOATing or POSITIONing techniques to create the illusion of columns. There are drawbacks to both approaches—floating requires “clearing” and positioning limits a layout’s flexibility.</p>
<p>Positioning was the early answer to CSS layouts. It remains a viable option and many examples of its use are widely published on the Internet as “the” answer.</p>
<p>Use Float, it offers flexibility. Accessibility requirements may mean that text needs to be resized, which could cause broken layouts for positioned columns.</p>
<h3><a title="_Toc256266240" name="_Toc256266240"></a>Applying Styles to HTML</h3>
<p>Styles should always be applied with a CLASS attribute. Only use the ID attribute when absolutely necessary. Applying a style inline with the STYLE attribute should also only be used when necessary.</p>
<h3><a title="_Toc256266241" name="_Toc256266241"></a>CSS Shortcuts</h3>
<p>Use of CSS shortcuts is a great way to slim down your code. You should use every opportunity to group styles and use shortcuts.</p>
<p><code><span style="font-size: 10pt">Example: <o:p></o:p></span></code></p>
<p><code><span style="font-size: 10pt">.foo {margin-top: 11px; margin-right: 11px; margin-bottom: 11px; margin-left: 11px;}<br />
.foo2 {margin-top: 11px; margin-right: 11px; margin-bottom: 11px; margin-left: 11px;}<o:p></o:p></span></code></p>
<p><code><span style="font-size: 10pt">Could be: <o:p></o:p></span></code></p>
<p><code><span style="font-size: 10pt">.foo, .foo2 {margin: 11px;}<o:p></o:p></span></code></p>
<h3><a title="_Toc256266242" name="_Toc256266242"></a>Use a Reset</h3>
<p>Consider using a reset. Resets essentially eliminate browser inconsistencies such as heights, font sizes, margins, headings, etc. The reset allows your layout look consistent in all browsers.</p>
<p>Reference to reset.css: <a href="http://developer.yahoo.com/yui/build/reset/reset.css">http://developer.yahoo.com/yui/build/reset/reset.css</a></p>
<p style="border: 1pt solid windowtext; padding: 1pt; background: none repeat scroll 0% 0% #cccccc">&nbsp;</p>
<p class="MsoMessageHeader">NOTE: <span>     </span>This technique to be only used if necessary on certain pages.</p>
<h3><a title="_Toc256266243" name="_Toc256266243"></a>Organize the Stylesheet with a Top-down Structure</h3>
<p>Lay your stylesheet out in a way that allows you to quickly find parts of your code. Consider top-down format that tackles styles as they appear in the source code. So, an example stylesheet might be ordered like this:</p>
<ol start="1" type="1">
<li class="MsoNormal">Generic classes (body, a, p,      h1, etc.)</li>
<li class="MsoNormal">#header</li>
<li class="MsoNormal">#nav-menu</li>
<li class="MsoNormal">#main-content</li>
</ol>
<p class="MsoNormal">Comment each section!</p>
<p class="MsoNormal" style="margin-left: 0.25in"><span class="comment">/****** main content *********/</span></p>
<p class="MsoNormal" style="margin-left: 0.25in">styles goes here&#8230;</p>
<p class="MsoNormal" style="margin-left: 0.25in"><span class="comment">/****** footer *********/</span></p>
<p class="MsoNormal" style="margin-left: 0.25in">styles go here&#8230;</p>
<h3><a title="_Toc256266244" name="_Toc256266244"></a>Use CSS Compressors</h3>
<p>CSS compressors help shrink CSS file size by removing line breaks, white spaces, and combining elements. This combination can greatly reduce the file size, which speeds up browser loading. Yahoo YUI compressor can be used.</p>
<pre style="margin-top: 12pt">java -jar yuicompressor-x.y.z.jar [options] [input file]</pre>
<pre style="margin-top: 12pt">More info can e found at <a href="http://developer.yahoo.com/yui/compressor/">http://developer.yahoo.com/yui/compressor/</a></pre>
<pre style="margin-top: 12pt"></pre>
<h3><a title="_Toc256266245" name="_Toc256266245"></a>Add Margins and Padding to All</h3>
<p>Different browsers render elements differently. IE renders certain elements differently than Firefox. IE 6 renders elements differently than IE 7 and IE 8. While the browsers are starting to adhere more closely to W3C standards, they&#8217;re still not perfect.</p>
<p>One of the main differences between versions of browsers is how padding and margins are rendered. If you&#8217;re not already using a reset, you might want to define the margin and padding for all elements on the page, to be on the safe side. You can do this quickly with a global reset, like so:</p>
<p class="MsoNormal" style="margin-left: 0.25in">* {<span class="keyword">margin</span>:0; <span class="keyword">padding</span>:0;}</p>
<h2><a title="_Toc256266246" name="_Toc256266246"></a>JavaScript Best Practices</h2>
<p class="MsoNormal"><o:p> </o:p></p>
<h3><a title="_Toc256266247" name="_Toc256266247"></a>Stick to a strict coding style</h3>
<p>Browsers are very forgiving when it comes to JavaScript syntax. This should not however be a reason for you to write sloppy code that relies on browsers to make it work.</p>
<p>The easiest way to check the syntactical quality of your code is to run it through</p>
<p><a href="http://www.jslint.com/"><span> </span>JSLint — a JavaScript validation tool</a> that gives you a detailed report about the syntax warnings and their meaning.</p>
<p>Clean and valid code means less confusing bugs to fix, easier handover to other developers and better code security. When you rely on hacks to get your code to work it is likely that there is also a security exploit that uses the same hacks. In addition, as hacks get fixed in browsers, your code will cease to work in the next version of the browser.</p>
<h3><a title="bdGEID" name="bdGEID"></a><a title="_Toc256266248" name="_Toc256266248"></a><span>Avoid mixing with other technologies</span><span></span></h3>
<p><span>Whilst it is possible to create everything you need in a document using JavaScript and the DOM it is not necessarily the most effective way of doing so. The following code puts a red border around every input field when its class is “mandatory” and there’s nothing in it.</span></p>
<pre><span><code>var f = document.getElementById('mainform');<o:p></o:p></code></span></pre>
<pre><span><code>var inputs = f.getElementsByTagName('input');<o:p></o:p></code></span></pre>
<pre><span><code>for(var i=0,j=inputs.length;i&lt;j;i++){<o:p></o:p></code></span></pre>
<pre><span><code><span>  </span>if(inputs[i].className === &#8216;mandatory&#8217; &amp;&amp;<o:p></o:p></code></span></pre>
<pre><span><code><span>     </span>inputs[i].value === &#8221;){<o:p></o:p></code></span></pre>
<pre><span><code><span>    </span>inputs[i].style.borderColor = &#8216;#f00&#8242;;<o:p></o:p></code></span></pre>
<pre><span><code><span>    </span>inputs[i].style.borderStyle = &#8217;solid&#8217;;<o:p></o:p></code></span></pre>
<pre><span><code><span>    </span>inputs[i].style.borderWidth = &#8216;1px&#8217;;<o:p></o:p></code></span></pre>
<pre><span><code><span>  </span>}<o:p></o:p></code></span></pre>
<pre><span><code>}</code></span></pre>
<p><span>This works, however it means that if you later need to make a change to these styles you need to go through the JavaScript and apply the changes there. The more complex the change is the harder it’ll be to edit this. Furthermore, not every JavaScript developer is proficient or interested in CSS, which means there’ll be a lot of back and forth until the outcome is reached. By adding a class called “error” to the element when there is an error, you can ensure that the styling information is kept inside the CSS, which is more appropriate:</span></p>
<pre><span><code>var f = document.getElementById('mainform');<o:p></o:p></code></span></pre>
<pre><span><code>var inputs = f.getElementsByTagName('input');<o:p></o:p></code></span></pre>
<pre><span><code>for(var i=0,j=inputs.length;i&lt;j;i++){<o:p></o:p></code></span></pre>
<pre><span><code><span>  </span>if(inputs[i].className === &#8216;mandatory&#8217; &amp;&amp;<o:p></o:p></code></span></pre>
<pre><span><code><span>     </span>inputs[i].value === &#8221;){<o:p></o:p></code></span></pre>
<pre><span><code><span>    </span>inputs[i].className += &#8216; error&#8217;;<o:p></o:p></code></span></pre>
<pre><span><code><span>  </span>}<o:p></o:p></code></span></pre>
<pre><span><code>}</code></span></pre>
<p><span>This is much more efficient as CSS was meant to cascade through the document. Say for example you want to hide all DIVs with a certain class in a document. You could loop through all the DIVs, check their classes and then change their style collection. In newer browsers you could use a CSS selector engine and then alter the style collection. The easiest way however is to use JavaScript to set a class on a parent element and use syntax along the lines of </span><span><code><span style="font-size: 10pt">element.triggerclass div.selectorclass{}</span></code> in the CSS. Keep the job of actually hiding the DIVs to the CSS designer, as he’ll know the best way of doing that.</span></p>
<h3><span><a title="_Toc256266249" name="_Toc256266249"></a>IDed Element Retrieval</span></h3>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The preferred to retrieve an element reference from the DOM method would be the W3C Core DOM standard <code><span style="font-size: 10pt">document.getElementById</span></code> method which is supported on the widest number of browsers.</p>
<h3><a title="_Toc256266250" name="_Toc256266250"></a>Reference Forms and Form Elements Correctly</h3>
<p>All forms in an HTML form should have a name attribute. For XHTML documents, the name attribute is not required and instead the form tag should have an id attribute and should be referenced using document.getElementById(). Referencing forms using indexes, such as document.forms[0] is a bad practice in almost all cases. Some browsers make the form available as a property of the document itself using its name. This is not reliable and shouldn&#8217;t be used.</p>
<p>The example below uses square bracket notation and correct object references to show the most fool-proof way of referencing a form input.</p>
<p class="MsoNormal">Correct Reference To Form Input</p>
<pre>document.forms["formname"].elements["inputname"]</pre>
<pre><o:p> </o:p></pre>
<p class="MsoNormal">Bad Practice</p>
<pre>document.formname.inputname
 <!--[if !supportLineBreakNewLine]-->
 <!--[endif]--></pre>
<h3><a title="_Toc256266251" name="_Toc256266251"></a>Avoid document.all</h3>
<p>document.all was introduced by Microsoft in IE and is not a standard javascript DOM feature. Although many newer browsers do support it to try to support poorly-written scripts that depend on it, many browsers do not.</p>
<p>There is never a reason to use document.all in javascript except as a fall-back case when other methods are not supported and very early IE support (&lt;5.0) is required. You should never use document.all support as a way to determine if the browser is IE, since other browsers also now support it.</p>
<h3><a title="_Toc256266252" name="_Toc256266252"></a>Don&#8217;t Use HTML Comments In Script Blocks</h3>
<p>In the ancient days of javascript (1995), some browsers like Netscape 1.0 didn&#8217;t have any support or knowledge of the script tag. So when javascript was first released, a technique was needed to hide the code from older browsers so they wouldn&#8217;t show it as text in the page. The &#8216;hack&#8217; was to use HTML comments within the script block to hide the code.</p>
<p class="MsoNormal">Using HTML Comments in Script is bad</p>
<pre>&lt;script language="javascript"&gt;</pre>
<pre>&lt;!--</pre>
<pre><span>   </span>// code here</pre>
<pre>//--&gt;</pre>
<pre>&lt;/script&gt;</pre>
<p>No browsers in common use today are ignorant of the &lt;script&gt; tag, so hiding of javascript source is no longer necessary. In fact, it can be considered harmful for the following reasons:</p>
<ul type="disc">
<li class="MsoNormal">Within XHTML documents, the      source will actually be hidden from all browsers and rendered useless</li>
<li class="MsoNormal">&#8211; is not allowed within HTML      comments, so any decrement operations in script are invalid</li>
</ul>
<h3><a title="_Toc256266253" name="_Toc256266253"></a>Use Correct &lt;script&gt; Tags</h3>
<p>The LANGUAGE attribute is deprecated in the &lt;script&gt; tag. The proper way to create a javascript code block is:</p>
<pre>&lt;script type="text/javascript"&gt;</pre>
<pre>// code here</pre>
<pre>&lt;/script&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/51/css-and-javascript-best-practices/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Multiple Browser Coding Guidelines</title>
		<link>http://tech.gpuri.com/50/multiple-browser-coding-guidelines/</link>
		<comments>http://tech.gpuri.com/50/multiple-browser-coding-guidelines/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 04:06:42 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[Browser]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/50/multiple-browser-coding-guidelines/</guid>
		<description><![CDATA[
The features of different Web browsers, such as CSS and JavaScript support, can cause Web applications to work differently from one browser to another. This lack of continuity among browsers not only causes an application to look bad, but it often causes it to break.
Acid3 Test
 Acid3 is a test from the Web Standards Project that [...]]]></description>
			<content:encoded><![CDATA[<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="ProgId" content="Word.Document" /><meta name="Generator" content="Microsoft Word 11" /><meta name="Originator" content="Microsoft Word 11" /></p>
<p>The features of different Web browsers, such as CSS and JavaScript support, can cause Web applications to work differently from one browser to another. This lack of continuity among browsers not only causes an application to look bad, but it often causes it to break.<o:p></o:p></p>
<h3><a title="_Toc256266227" name="_Toc256266227"></a>Acid3 Test</h3>
<p class="MsoNormal"><strong><o:p> </o:p></strong><span>Acid3</span> is a test from the Web Standards Project that checks how well a web browser follows certain selected elements from web standards, especially relating to the Document Object Model (DOM) and JavaScript.</p>
<p class="MsoNormal"><o:p> </o:p>Acid3 test focuses on technologies used on modern, highly interactive websites characteristic of Web 2.0, such as ECMAScript, HTML 4.01 Strict, XHTML 1.0 Strict and DOM Level 2. It includes several elements from the CSS2 recommendation that were later removed in CSS2.1 but reintroduced in World Wide Web Consortium (W3C) CSS3 working drafts.<span style="font-size: 14pt"><o:p><br />
</o:p></span></p>
<table class="MsoTableGrid" style="border-collapse: collapse; border: medium none" border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 2.05in; border: 1pt solid windowtext; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-size: 14pt">Layout   Engine<o:p></o:p></span></strong></p>
</td>
<td style="width: 2.05in; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-size: 14pt">Browser<o:p></o:p></span></strong></p>
</td>
<td style="width: 2.05in; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: windowtext windowtext windowtext -moz-use-text-color; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="font-size: 14pt">Acid3 Score<o:p></o:p></span></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Presto<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Opera 10<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>100/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td rowspan="2" style="width: 2.05in; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>WebKit<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Safari 4.0<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>100/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Chrome 4.0<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ccffcc; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>100/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td rowspan="4" style="width: 2.05in; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Gecko<o:p></o:p></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><strong><o:p> </o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Firefox 3.5.7<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>93/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Firefox 3.6<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>94/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Firefox 3.7a2<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>97/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="color: blue">Firefox 4.0<o:p></o:p></span></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% #ffcc00; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="color: blue">?/100<o:p></o:p></span></strong></p>
</td>
</tr>
<tr>
<td rowspan="4" style="width: 2.05in; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color windowtext windowtext; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>Trident<o:p></o:p></strong></p>
<p class="MsoNormal" style="text-align: center" align="center"><strong><o:p> </o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>IE 6.0<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>12/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>IE 7.0<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>14/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>IE 8.0<o:p></o:p></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong>20/100<o:p></o:p></strong></p>
</td>
</tr>
<tr>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="color: blue">IE 9.0<o:p></o:p></span></strong></p>
</td>
<td style="width: 2.05in; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color windowtext windowtext -moz-use-text-color; background: none repeat scroll 0% 0% red; padding: 0in 5.4pt" valign="top" width="197">
<p class="MsoNormal" style="text-align: center" align="center"><strong><span style="color: blue">32/100<o:p></o:p></span></strong></p>
</td>
</tr>
</table>
<p class="MsoNormal" style="text-align: center" align="center"><span style="font-size: 10pt">Acid3 Test Score Chart<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<h3><a title="_Toc256266228" name="_Toc256266228"></a>Tool of Choice</h3>
<p class="MsoNormal"><o:p> </o:p>One can handle most of the browser issues by using hacks but hacks are dangerous. Since they are based on non-standard exploits, you can’t predict how they are going to behave in future browsers. The tool of choice for fighting these problems is the conditional Stylesheet and JavaScript. Browsers provide comment tags, to target specific versions, as well as greater-than/less-than stuff for targeting multiple versions at once.<o:p><br />
</o:p></p>
<h3><a title="_Toc256266229" name="_Toc256266229"></a>Conditional Stylesheets and JavaScripts</h3>
<p class="MsoNormal"><o:p> </o:p>The core idea is based on the method of Conditional Comments found in Internet Explorer, extended to include other browsers, and to move the conditional statements inline with your CSS definitions.<o:p><br />
</o:p></p>
<p class="MsoNormal">Conditional-CSS isn&#8217;t really all that interested in which browser the user using, but rather what is rendering engine the user&#8217;s browser utilizes. This is why Conditional-CSS uses &#8216;Gecko&#8217; rather than the well known Firefox as one of its <em>browser</em> conditions. Likewise for Safari &#8216;Webkit&#8217; is used. This allows other browsers using the same rendering engines to receive the same targeted CSS. An exception to this rule is made for IE (rather than using &#8216;Trident&#8217;) since this is what the IE conditional comments use and Trident isn&#8217;t particularly well known. Similarly for Opera, since only the Opera browser uses it&#8217;s Presto rendering engine, &#8216;Opera&#8217; is used.<o:p><br />
</o:p></p>
<h3><a title="_Toc256266230" name="_Toc256266230"></a>How to go about it?<o:p><br />
</o:p></h3>
<ol style="margin-top: 0in" start="1" type="1">
<li class="MsoNormal">Choose      one of the standard conforming browsers (Acid3 score 100/100) like Chrome 4.0      or Opera 10 to create and test a standard compliant Stylesheets and JavaScripts      common for all browsers.</li>
<li class="MsoNormal">Create      a separate Stylesheet and Javascripts for each of the browser versions you      want to target e.g. IE and Firefox versions.</li>
<li class="MsoNormal">Include      the Stylesheets and JavaScripts from step 2 by using conditional comments.      This overrides the statements in the common CSS and javaScript file      created in step 1.</li>
</ol>
<p class="MsoNormal"><o:p> </o:p><code><span style="font-size: 10pt">&lt;!&#8211;[if IE]&gt; &lt;style type=&#8221;text/css&#8221;&gt;@import &#8220;IE-override.css&#8221;;&lt;/style&gt; &lt;![endif]&#8211;&gt;</span></code></p>
<p class="MsoNormal"><o:p> </o:p>This CSS file is only loaded if the detected browser is IE, otherwise it won&#8217;t. You should put this conditional statement into the head of your html file after every other CSS import code. It should be the last in the list, so that it overwrites the main css files:<code><span style="font-size: 10pt"><o:p></o:p></span></code></p>
<p class="MsoNormal"><o:p> </o:p>Now if for example you had a statement in your main.css file: <code><span style="font-size: 10pt">#logo { margin:10px }</span></code> and it doesn&#8217;t work properly in IE, you can add the same statement with a different value in your IE-override.css file: <code><span style="font-size: 10pt">#logo { margin:20px }</span></code>.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<h3><a title="_Toc256266231" name="_Toc256266231"></a>The Conditional Comment Code Examples</h3>
<p class="MsoNormal"><o:p> </o:p>The syntax to note is “!” stand for “not”, so !IE means “not IE”. gt means “greater than”, gte means “greater than or equal”, lt means “less than”, lte means “less than or equal.”<o:p><br />
</o:p></p>
<p class="MsoNormal">Target ALL VERSIONS of IE</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if IE]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;all-ie-only.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target everything EXCEPT IE</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if !IE]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;not-ie.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target IE 7 ONLY</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if IE 7]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie7.css&#8221;&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target IE 6 ONLY</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if IE 6]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie6.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target IE 6 and LOWER</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if lt IE 7]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie6-and-down.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if lte IE 6]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie6-and-down.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target IE 7 and LOWER</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if lt IE 8]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie7-and-down.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if lte IE 7]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie7-and-down.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Target IE 8 and LOWER</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if lt IE 9]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie8-and-down.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if lte IE 8]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie8-and-down.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal">Target IE 6 and HIGHER</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if gt IE 5.5]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie6-and-up.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if gte IE 6]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie6-and-up.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target IE 7 and HIGHER</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if gt IE 6]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie7-and-up.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if gte IE 7]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie7-and-up.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>Target IE 8 and HIGHER</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if gt IE 7]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie8-and-up.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p class="MsoNormal"><o:p> </o:p>&lt;!&#8211;[if gte IE 8]&gt;</p>
<p class="MsoNormal"><span>            </span>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;ie8-and-up.css&#8221; /&gt;</p>
<p class="MsoNormal">&lt;![endif]&#8211;&gt;</p>
<p><span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/50/multiple-browser-coding-guidelines/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Oracle OLAP Option</title>
		<link>http://tech.gpuri.com/49/oracle-olap-option/</link>
		<comments>http://tech.gpuri.com/49/oracle-olap-option/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 02:14:16 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/49/oracle-olap-option/</guid>
		<description><![CDATA[The Oracle 10g Enterprise Edition OLAP Option extends the analytic capabilities of the Oracle database by providing new multidimensional datatypes, a multidimensional calculation engine, and a framework to build OLAP applications using SQL, PL/SQL and Java. Uniquely, the OLAP Option uses the Oracle database to store and manage its data, allowing you to take advantage [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.dbazine.com/datawarehouse/dw-articles/rittman1">Oracle 10<em>g</em> Enterprise Edition OLAP Option</a> extends the analytic capabilities of the Oracle database by providing new multidimensional datatypes, a multidimensional calculation engine, and a framework to build OLAP applications using SQL, PL/SQL and Java. Uniquely, the OLAP Option uses the Oracle database to store and manage its data, allowing you to take advantage of the scalability, reliability and manageability of the Oracle 10<em>g </em>platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/49/oracle-olap-option/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How To Create an IE-Only Stylesheet</title>
		<link>http://tech.gpuri.com/48/how-to-create-an-ie-only-stylesheet/</link>
		<comments>http://tech.gpuri.com/48/how-to-create-an-ie-only-stylesheet/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 23:23:25 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[Browser]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/48/how-to-create-an-ie-only-stylesheet/</guid>
		<description><![CDATA[The tool of choice for fighting IE problems is the conditional stylesheet. IE provides comment tags, supported all the way up to the current IE 8 to target specific versions, as well as greater-than/less-than stuff for targeting multiple versions at once.
Why use conditional stylesheets?

You got problems, they need fixin’
Keeps your code hack-free and valid
Keeps your [...]]]></description>
			<content:encoded><![CDATA[<p>The tool of choice for fighting IE problems is the <a href="http://css-tricks.com/how-to-create-an-ie-only-stylesheet/"><strong>conditional stylesheet</strong></a>. IE provides comment tags, supported all the way up to the current IE 8 to target specific versions, as well as greater-than/less-than stuff for targeting multiple versions at once.</p>
<h4>Why use conditional stylesheets?</h4>
<ul>
<li>You got problems, they need fixin’</li>
<li>Keeps your code hack-free and valid</li>
<li>Keeps your main stylesheet clean</li>
<li>Perfectly acceptable technique, sanctioned by Microsoft</li>
</ul>
<p>1.    Create a stylesheet and javascript common for all browser, without using any hacks to work around rendering problems in MSIE<br />
2.    Create a stylesheet and javascripts common for all versions of MSIE.<br />
3.    Create a separate stylesheet and javascripts for each of the MSIE versions you want to target.<br />
4.    Include the stylesheets and javascripts from 2 and 3 by using conditional comments.</p>
<p>One good example can be found at <a href="http://www.gpuri.com">http://www.gpuri.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/48/how-to-create-an-ie-only-stylesheet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Inject Google analytics code in HTML pages</title>
		<link>http://tech.gpuri.com/47/inject-google-analytics-code-in-html-pages/</link>
		<comments>http://tech.gpuri.com/47/inject-google-analytics-code-in-html-pages/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 22:43:01 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/47/inject-google-analytics-code-in-html-pages/</guid>
		<description><![CDATA[To update your HTML/JSP/PHP pages with the google analytics you can
use UNIX sed command and inject the two scripts provided for your
website by google analytics. Below is the code. This code replaces
&#60;/body&#62; tag with the scripts and &#60;/body&#62; tag.

find ./ -type f -iname &#8220;*.htm&#8221; &#124; xargs sed -i &#8217;s/&#60;\/body&#62;/&#60;script
type=\&#8221;text\/javascript\&#8221;&#62; var gaJsHost = \(\(&#8221;https:&#8221; ==
document.location.protocol\) ? [...]]]></description>
			<content:encoded><![CDATA[<pre>To update your HTML/JSP/PHP pages with the google analytics you can</pre>
<pre>use UNIX sed command and inject the two scripts provided for your</pre>
<pre>website by google analytics. Below is the code. This code replaces</pre>
<pre>&lt;/body&gt; tag with the scripts and &lt;/body&gt; tag.</pre>
<pre></pre>
<pre><font color="#0000ff">find ./ -type f -iname &#8220;*.htm&#8221; | xargs sed -i &#8217;s/&lt;\/body&gt;/&lt;script</font></pre>
<pre><font color="#0000ff">type=\&#8221;text\/javascript\&#8221;&gt; var gaJsHost = \(\(&#8221;https:&#8221; ==</font></pre>
<pre><font color="#0000ff">document.location.protocol\) ? &#8220;https:\/\/ssl.&#8221; : &#8220;http:\/\/www.&#8221;\);</font></pre>
<pre><font color="#0000ff">document.write\(unescape\(&#8221;%3Cscript src=&#8217;\&#8221;&#8221; + gaJsHost +</font></pre>
<pre><font color="#0000ff">&#8220;google-analytics.com\/ga.js&#8217;\&#8221; type=&#8217;\&#8221;text\/javascript</font></pre>
<pre><font color="#0000ff">&#8216;\&#8221;%3E%3C\/script%3E&#8221;\)\);</font></pre>
<pre><font color="#0000ff"> &lt;\/script&gt;&lt;script type=&#8221;text\/javascript&#8221;&gt; try { var pageTracker</font></pre>
<pre><font color="#0000ff"> = _gat._getTracker\(&#8221;UA-XXXXXXX-X&#8221;\); pageTracker._trackPageview\(\);</font></pre>
<pre><font color="#0000ff"> } catch\(err\) {}&lt;\/script&gt; &lt;\/body&gt;/g&#8217;</font></pre>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/47/inject-google-analytics-code-in-html-pages/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reduce code noise with Groovy</title>
		<link>http://tech.gpuri.com/46/reduce-code-noise-with-groovy/</link>
		<comments>http://tech.gpuri.com/46/reduce-code-noise-with-groovy/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 03:06:33 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[Groovy]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/46/reduce-code-noise-with-groovy/</guid>
		<description><![CDATA[Groovy&#8217;s concise syntax frees developers from typical Java™ constructs that are required for code compilation but don&#8217;t facilitate expressing what a program is really trying to accomplish. In this revival of the Practically Groovy series, Groovy developer and guest columnist J. Scott Hickey walks you through a series of comparisons between normal Java code and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ibm.com/developerworks/java/library/j-pg09196.html">Groovy&#8217;s</a> concise syntax frees developers from typical Java™ constructs that are required for code compilation but don&#8217;t facilitate expressing <em>what</em> a program is really trying to accomplish. In this revival of the <em>Practically Groovy</em> series, Groovy developer and guest columnist J. Scott Hickey walks you through a series of comparisons between normal Java code and the same Groovy code to show you how this exciting language frees you to focus on the important aspects of coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/46/reduce-code-noise-with-groovy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JBoss ESB</title>
		<link>http://tech.gpuri.com/45/jboss-esb/</link>
		<comments>http://tech.gpuri.com/45/jboss-esb/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 20:43:05 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[ESB]]></category>

		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/45/jboss-esb/</guid>
		<description><![CDATA[If SOA is too expensive, complex or politically challenging, the technology won’t take off. How, then, is it possible to build an SOA that overcomes political and cost constraints? Driving an SOA strategy to success in a large organization requires a corporate-level CIO with the power to drive a vision, enforce a set of architectural [...]]]></description>
			<content:encoded><![CDATA[<p>If SOA is too expensive, complex or politically challenging, the technology won’t take off. How, then, is it possible to build an SOA that overcomes political and cost constraints? Driving an SOA strategy to success in a large organization requires a corporate-level CIO with the power to drive a vision, enforce a set of architectural goals and blueprints, and mediate financial allocations. <a href="http://www.mastertheboss.com/en/soa-a-esb/78-jboss-esb.html">To get a manageable SOA</a>, you’ll need to start with SOA platforms that represent a <em>relatively low investment</em>. That’ll likely mean tools and platforms that are open source, with support and ecosystem benefits available at a low cost.</p>
<p>JBoss team have designed their own Service Bus: JBoss Enterprise Service Bus  is a robust SOA solution designed since the release 4.2 with build-in fail-over, load balancing and delayed message redelivery. JBossESB allows you to distribute service instances across many nodes. Each node can be a virtual or physical machine running one or more instances of JBossESB.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/45/jboss-esb/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to use the agent sample application in WebLogic 10 - OpenSSO</title>
		<link>http://tech.gpuri.com/44/how-to-use-the-agent-sample-application/</link>
		<comments>http://tech.gpuri.com/44/how-to-use-the-agent-sample-application/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 22:32:28 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[SSO]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/44/how-to-use-the-agent-sample-application/</guid>
		<description><![CDATA[This document describes to use the agent sample application in conjunction with the Weblogic 10.X Application Server and the J2EE Agent. Please note thatthe agent needs to be installed first before deploying this sample application.
]]></description>
			<content:encoded><![CDATA[<p>This document describes <a href="http://tech.gpuri.com/wp-content/uploads/2009/01/j2ee-policy-agent-demo-on-bea-wl10.doc" title="to use the agent sample application">to use the agent sample application</a> in conjunction with the Weblogic 10.X Application Server and the J2EE Agent. Please note thatthe agent needs to be installed first before deploying this sample application.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/44/how-to-use-the-agent-sample-application/feed/</wfw:commentRss>
		</item>
		<item>
		<title>OpenSSO Fedlet Demo</title>
		<link>http://tech.gpuri.com/42/fedlet-demo/</link>
		<comments>http://tech.gpuri.com/42/fedlet-demo/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 22:28:05 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[SSO]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/42/fedlet-demo/</guid>
		<description><![CDATA[I will try to demonstrate an IDP generating Fedlets, SP configuring and using this Fedlet for IDP initiated SSO, SP initiated SSO and transfer of identity attributes as part of the assertions from the IDP.
Here&#8217;s also the details and a write-up of steps of steps, which I&#8217;ve used for the setup.
]]></description>
			<content:encoded><![CDATA[<p>I will try to demonstrate an IDP generating Fedlets, SP configuring and using this Fedlet for IDP initiated SSO, SP initiated SSO and transfer of identity attributes as part of the assertions from the IDP.</p>
<p>Here&#8217;s also the <a href="http://tech.gpuri.com/wp-content/uploads/2009/01/fedlets-demo.doc" title="fedlets-demo.doc">details and a write-up of steps</a> of steps, which I&#8217;ve used for the setup.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/42/fedlet-demo/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Adobe Flex in JSR-286 Portlets</title>
		<link>http://tech.gpuri.com/38/using-adobe-flex-in-jsr-286-portlets/</link>
		<comments>http://tech.gpuri.com/38/using-adobe-flex-in-jsr-286-portlets/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 21:04:44 +0000</pubDate>
		<dc:creator>gpuri</dc:creator>
		
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://tech.gpuri.com/38/using-adobe-flex-in-jsr-286-portlets/</guid>
		<description><![CDATA[This article shall show you how the Adobe Flex SDK can be used in a Portal environment to enhance the user interface for a Portlet. It has also previously been possible to use Flex with JSR-168 Portlets and alike [FlexPortal], but with the new Portlet 2.0 specification (JSR-286) some things have improved, such as the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www-10.lotus.com/ldd/portalwiki.nsf/dx/Flex_Demo_Portlet_v5.pdf/$file/Flex_Demo_Portlet_v5.pdf">This article shall show</a> you how the Adobe Flex SDK can be used in a Portal environment to enhance the user interface for a Portlet. It has also previously been possible to use Flex with JSR-168 Portlets and alike [FlexPortal], but with the new Portlet 2.0 specification (JSR-286) some things have improved, such as the support for asynchronous requests, public render parameters and events. It will be shown what is possible with the technology combination Flex/Portlets and where the limits are.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.gpuri.com/38/using-adobe-flex-in-jsr-286-portlets/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 3.556 seconds -->
<!-- Cached page served by WP-Cache -->
