A little while ago, it was pointed out to me that my Hayden Panettiere Free ColdFusion eCard system was not working in Internet Explorer 6. Because I am working on Windows Vista (and trying every day not to throw the computer out my window), I don't have ready access to IE6. However, since it was working in IE7 and FireFox, I have to admit, I sort of brushed this comment off and didn't pay it much head. However, I finally did get my hands a computer that had IE6 and did some testing. And, sure enough, in IE6, you couldn't get to the Preview eCard screen - it would keep kicking you out to the homepage.
After doing some quick CFDumping of the FORM and URL scopes, the problem was bewildering but obvious; CFLocation didn't seem to be handling URL hash values very well with IE6. To demonstrate what I mean, take a look at this sample code that I set up:
<!--- Check to see if we have the redirect command. ---> <cfif StructKeyExists( URL, "redirect" )> <cflocation url="./index.cfm?id=123##top-of-page" addtoken="false" /> </cfif> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Untitled</title> </head> <body> <h1> Redirect Test With URL Hash </h1> <p> <a href="./index.cfm?redirect">Redirect with hash</a> </p> <!--- Dump out URL scope. ---> <cfdump var="#URL#" label="URL Scope" /> </body> </html>
Here, we are providing a link that will trigger a CFLocation tag. That ColdFusion CFLocation tag has both an URL parameter (ID) and a hash value (#top-of-page). When this CFLocation is triggered in FireFox, it acts as expected and the proper ID value is moved to the URL scope:
However, when this page is run in IE6, we get the following output:
Notice that the hash value (#top-of-page) is read out of the URL as part of the ID parameter. This is the strangest bug! I have no idea why this is happening and why it only happens in IE6?!? Hash values are part of the HTTP protocol, are they not? Am I just not seeing something very obvious in the code? This must be a bug in IE6... but then again, why would it have any affect on ColdFusion? These two applications are running in totally different places.
To fix this, I simply put an ampersand before the hash:
<cflocation url="./index.cfm?id=123&##top-of-page" addtoken="false" />
This works fine and doesn't add any extra values to the URL scope. Strangest thing. Does anyone understand why this would be happening?
Want to use code from this post? Check out the license.