This is really cool. I modified this to make it possible to differentiate HTTP/S protocols. If you are running a web site where you have both secure (HTTPS) and unsecured (HTTP) information, but want certain data to only show up on the secure pages, this will do it. On the clients’ machine, when downloading the html from the web server, this javascript will detect what protocol is being utilized (either regular HTTP or HTTPS) and render the code accordingly. I modified the code for my Google Analytics tags so that when using HTTPS it will utilize https://ssl.google-analytics.com/urchin.js for secure connections instead of http://www.google-analytics.com/urchin.js for the unsecured connections. I’ll show you my example code:

<script language=”JavaScript” type=”text/JavaScript”>
if (window.location.protocol.indexOf(‘https:’)==0?’s’:”)
{
document.write(‘<scr’+’ipt src=”https://ssl.google-analytics.com/urchin.js” type=”text/javascript”>’);
document.write(‘<scr’+’ipt src=”/google.js” type=”text/javascript”>’);
}

else
{
document.write(‘<scr’+’ipt src=”http://www.google-analytics.com/urchin.js” type=”text/javascript”>’);
document.write(‘<scr’+’ipt src=”/google.js” type=”text/javascript”>’);
}
</script>