I spent some time scratching my head over this one and thought I’d share.
<cfset userAgent = trim(listGetAt(CGI.HTTP_USER_AGENT, 2, ';'))> <!--- This only works for IE ---> <cfset outtaDate = 'MSIE 8.0, MSIE 7.0b, MSIE 7.0, MSIE 6.1, MSIE 6.01, MSIE 6.0b, MSIE 6.0'> <!--- List all the versions of IE that are out of date ---> <cfif ListFindNoCase(outtaDate, userAgent, ',') NEQ 0> <!--- We're not gonna bump em from the site, but we will display a warning to those visitors using the older versions of IE ---> <div class="outtaDate">You are using an out of date version of Internet Explorer and this site <b>WILL NOT</b> display correctly. If you are using Windows Vista or Windows 7, please use Windows Update and upgrade to Internet Explorer 9 or newer. If you are using Windows XP and earlier which cannot upgrade to Internet Explorer 9, please download the latest version of <a href="http://www.mozilla.org" target="_blank">Firefox</a>, <a href="http://www.google.com/chrome" target="_blank">Chrome</a>, <a href="http://www.opera.com" target="_blank">Opera</a> or <a href="http://www.apple.com/safari/" target="_blank">Safari</a> to see this site correctly.</div> </cfif>
I’m using this code to identify older versions of IE that don’t support CSS3 and/or HTML5. Maybe I should be identifying browsers a better way, but the problem here lies within the listGetAt on line 1.
This code will trip up the W3C Markup Validation Service marking your code invalid with one of ColdFusion’s styles from an error… ColdFusion’s pumping out an error to the service… even though the running site won’t pump out an error at all.
Here is ColdFusion’s exception error to the W3C service:
In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list.
I’m sure this isn’t a big deal since most people aren’t identifying browsers with their code or even coding in HTML5 for that matter, let alone valid HTML5 to use the W3C service (hopefully it’s more than I think).
Either way, I don’t know why the validator service is getting that error, having tested the code on virtually every browser without any problems (old and current alike). And I can’t really tell whether the problem is with CF or the W3C’s tool, but it’s not having any sort of effect on the live code, which is always a good thing.