Created
April 9, 2010 05:15
-
-
Save subtleGradient/360913 to your computer and use it in GitHub Desktop.
HTML5 Template with className states and browser detection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swap classes onload and domready | |
$(function(){ $('html').removeClass('not-ready').addClass('ready'); }); // jQuery | |
$(window).load(function(){ $('html').removeClass('loading').addClass('loaded'); }); | |
// target a specific version | |
if (navigator.isIE == 6){ | |
// do stuff for IE6 | |
} | |
// Deliever different behaviour for a group of IE versions | |
if (navigator.isIE < 9){ | |
// ie's notorious png-tranparent-pixels-go-black-on-fade issue | |
$('png-image').hide(); | |
} else { | |
$('png-image').hide(400); | |
} | |
// Check for IE generally | |
if (navigator.isIE){ | |
// do IE stuff | |
} else { | |
// do other stuff since NaN is falsey | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Swap classes onload and domready | |
document.addEvent('domready',function(){ $$('html').removeClass('not-ready').addClass('ready'); }); // MooTools | |
document.addEvent('load',function(){ $$('html').removeClass('loading').addClass('loaded'); }); // MooTools | |
// target a specific version | |
if (navigator.isIE == 6){ | |
// do stuff for IE6 | |
} | |
// Deliever different behaviour for a group of IE versions | |
if (navigator.isIE < 9){ | |
// ie's notorious png-tranparent-pixels-go-black-on-fade issue | |
$('png-image').setStyle('display','none'); | |
} else { | |
$('png-image').fade('out'); | |
} | |
// Check for IE generally | |
if (navigator.isIE){ | |
// do IE stuff | |
} else { | |
// do other stuff since NaN is falsey | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang=en class=no-js> | |
<head> | |
<meta http-equiv=Content-Type content="text/html; charset=UTF-8"> | |
<!--[if IE]><![endif]--> | |
<!--[if IE]><meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1"><![endif]--> | |
<title>Page Title - Site Title</title> | |
<meta name=description content=""> | |
<meta name=keywords content=""> | |
<meta name=author content=""> | |
<script>try{ | |
if(typeof navigator=='undefined')navigator={}; | |
HTML=document.getElementsByTagName('html')[0]; | |
HTML.className="js loading not-ready"; | |
HTML.className+=(this.top===this.window?' not-':' ')+'framed'; | |
}catch(e){}</script> | |
<meta name=viewport content="width=device-width; initial-scale=1.0;"> | |
<!--[if IE 9]><script>try{HTML.className+=' ie9'}catch(e){};navigator.isIE=9</script><![endif]--> | |
<!--[if IE 8]><script>try{HTML.className+=' ie8'}catch(e){};navigator.isIE=8</script><![endif]--> | |
<!--[if IE 7]><script>try{HTML.className+=' ie7'}catch(e){};navigator.isIE=7</script><![endif]--> | |
<!--[if IE 6]><script>try{HTML.className+=' ie6'}catch(e){};navigator.isIE=6</script><![endif]--> | |
<!--[if lt IE 6]><script>try{HTML.className+=' ie5'}catch(e){};navigator.isIE=5</script><![endif]--> | |
<!--[if gt IE 9]><script>try{HTML.className+=' ie10'}catch(e){};navigator.isIE=10</script><![endif]--> | |
<!--[if !IE]>--><script>try{HTML.className+=' not-ie'}catch(e){};navigator.isIE=NaN</script><!-- <![endif]--> | |
<link rel=stylesheet href="css/style.css?v=1"> | |
<link rel=stylesheet href="css/handheld.css?v=1" media=handheld> | |
<script src="js/modernizr.js?v=1"></script> | |
</head> | |
<body> | |
<div class=page> | |
<div class=head> | |
</div> | |
<div class=body> | |
<div class=leftCol> | |
</div> | |
<div class=rightCol> | |
</div> | |
<div class=main> | |
</div> | |
</div> | |
<div class=foot> | |
</div> | |
</div> | |
<script src="js/framework.js?v=1"></script> | |
<script src="js/app.js?v=1"></script> | |
<!--[if lt IE 7]><script src="js/dd_belatedpng.js?v=1"></script><![endif]--> | |
<script> | |
if(document.location.hash.indexOf('DEBUG')+1){ | |
document.write('<script src="js/profiling/yahoo-profiling.min.js?v=1"><\/script>'); | |
document.write('<script src="js/profiling/config.js?v=1"><\/script>'); | |
} | |
_gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']]; | |
;(function(d,t,src){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=true;g.src=src;s.parentNode.insertBefore(g,s)}) | |
(document,'script','//www.google-analytics.com/ga.js') | |
</script> | |
</body> | |
</html> |
Lately I've been avoiding using unnecessary semicolons in my JS. But since this is an HTML file I'm still going to keep using semicolons. Why? Because 'crazy stuff' can happen and I don't feel like thinking of every single crazy thing that could possible happen to be sure that it wouldn't break my stuff.
I'm using this file as the base for PHP, Rails, ASP classic, .NET, Django, etc…
So there's no telling if some random post-processor might be installed that I don't know about or something 'wacky'.
Since this edition adds the IE classnames using JS, you're not going to get those classnames when JS is disabled. If that's an issue for you then you should use conditional comments to create the body tag instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, I know that using
isIE
in your code is generally bad practice.I would never use it in library code.
But as a pragmatic developer, sometimes I just need to Get Stuff Done™