You are here

HTC components in XP Service Pack 2 (2)

The page getting by far the most hits on the site is my entry about HTC components in Windows XP SP2, due mostly thanks to a mention on Peter Nederlof's page about the csshover component (which I am currently using in the site, thanks!).

I got a couple of questions on how to change the mime type of HTC files, especially if you don't have access to some server settings, and/or you are not that .htaccess saffy. On I'm missing some override permissions, so I needed a workaround myself. Here's what I did...

I am using a PHP wrapper that sets the correct mime-type. Instead of referencing a HTC file directly, I am wrapping it through the PHP script.

Instead of: 
body { behavior: url( }
I am using
body { behavior: url(htcmime.php?

The htcmime.php file looks as follows:

// Get component file name
$fname = (array_key_exists("file", $_GET)) ? $_GET["file"] : "";
// basename() also strips \x00, we don't need to worry about ? and # in path:
// Must be real files anyway, fopen() does not support wildcards
$ext = array_pop(explode('.', basename($fname)));
if (strcasecmp($ext, "htc") != 0 || !file_exists($fname))
exit ("No file specified, file not found or illegal file.");

$flen = filesize($fname);
header("Content-type: text/x-component");
header("Content-Length: ".$flen);
header("Content-Disposition: inline; filename=$fname");
$fp = fopen($fname, "r");
echo fread($fp, $flen);

Update: If you're more of an ASP person, check out SpiritOfGrandeur's comment below. Thanks!



Is there any idea for HTC working on MAC OS X? I am using IE 5.2.3


Here is the code for ASP. Thanks for the writeup on all this HTC stuff :)

<%@ Language=VBScript %>
Dim sFile, fso, ts, aFileName, ext, nFile
Response.Expires = 0
sFile = Trim(Request.QueryString("file"))

If ( strcomp(sFile, vbNullString, 1 ) 0 ) then

Set fso = Server.CreateObject("Scripting.FileSystemObject")

aFileName = Split(sFile, ".")
ext = aFileName(uBound(aFileName))
nFile = server.mappath("./" & sFile)
if strcomp(ext, "htc", 1) = 0 AND fso.FileExists(nFile) then

Set f = fso.GetFile(nFile)
Response.ContentType = "text/x-component"
Response.AddHeader "Content-Length" , f.Size
Response.AddHeader "Content-Disposition" , "inline; filename=" & sFile
Set ts = fso.OpenTextFile( nFile, 1, true )
Response.Write ts.ReadAll()
Set ts = Nothing
Set f = Nothing
Response.Write("File not found or illegal file.")
end if
Set fso = Nothing
Response.Write("No file specified.")
end if

This code doesn't work for me. It appears that the first IF statement has a syntax error.

Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/chiptest/ASP/functions/hover.asp, line 6, column 39
If ( strcomp(sFile, vbNullString, 1 ) 0 ) then

Also, there's no real mention about what to do in the stylesheet when using this code. Is the following still accurate?

body { behavior: url( }

Ok you guys, I've tried my best to figure all this out for myself. I've already visited but I still can't seem to make the dropdown menu work for IE. My site is

I've even put an .htaccess in the wgn-test folder, I've even tried calling the host server and they said that they can see the drop down just fine in IE. I don't know why it won't work for me, and I'm pretty sure that the majority of my client's audience won't be able to see it in IE either. 

I would really appreciate any advice you can give to get this to work. Thank you kindkly, Donna.

My spoon is too big.


Did you ever figure out the problem? If so, I'd be curious what you did.

It seems to work, so I guess she figured it out (and likely won't be visiting this post again...)

your navigation doesn't even show up in Mac/IE. I don't mean the drop-down, the whole black bar is gone.

I'm trying to solve this htc hover issue myself and none of the examples work so far on Mac/IE. 5.17-5.23. just fyi.


I am considering IE for Mac a dead browser (as does Microsoft). I am sure it won't work with Netscape 4 either...

Note that IE for Mac is a totally different product than IE for Windows, and it doesn't support HTC or the stylesheet behaviors.

Im soooooo confused about mime type
isnt theri something I can just add to the htc itself?

-Thanks for all the great work!

Thankyou so much for this script. I had been trying to find some workaround for this problem for several hours now. Your php solution worked perfectly for me.

I can't seem to get this to work. I have wrapped the htc file in a php file. However, I still doesn't work in IE 6.0.29 on XP.

Do you have a copy of the HTC file you used? What the HTC file specific to this use of wrapping it in a PHP file or is it the same file that Peter came up with?

Thanks for this solution!
Have been looking for something like this for a white and it worked like a charm!

The HTC components/XP SP2 junk drove me nuts. Finally, though, I also used a wrapper for ColdFusion, very similar to the PHP and ASP examples with one minor difference: the "inline" value in the header needed to be dropped. Why? Good question but I don't have an answer and I couldn't find one on LiveDocs.

Here's the code for the wrapper:

cfheader name="Content-Disposition" value="" 
cfcontent type="text/x-component" file="C:\CFusionMX\wwwroot\filelocation\" deletefile="no" 

I saved the wrapper as csshover_wrap.cfm and...

 body { behavior: url(; } 


 body { behavior: url(csshover_wrap.cfm); } 

Great stuff!

If someone could point me to the right direction, I would be very thankful!

I tried this solution and the php solution, none of them solved the problem on IE 6.29 on SP2;

The CF solution also collapsed the lines of the menu on firefox

I would like to know how do I implement the ASP solution from above, since I'm a real newbie and don't know how to make the CSS call the htc through the ASP.

Anyway, thanks for these awesome tips... I hope the ASP will work, once I learn how to use it :D

I have followed instructions on this and Peter Nederlof's pages for creating css drop down menu, and everything works fine on my local server, but when I upload the site to the remote server, IE refuses to show the menu, even though it did show it (the same version, the same code) properly locally.

IE does not report any error, so I just can not locate the problem. I guess that if '' helps IE override its css bugs, then if it is unable to find/read/understand it, it won't be able to use it. So, I checked the path referring to the '', tried with proposed workaround for adjusting the mimetype, tried with adding the mimetype text/x-component for htc in my site's cPanel, and nothing worked.

Obviously, I am missing something, but I can not see what. If someone could point me to the right direction, I would be very thankful!

It sounds exactly like what you would see without the proper mimetype set. Do you have a link so one of us can check whether the mimetype is set correctly on your server?

Thanks for help!

The link you provided has CSS menus that work fine for me in IE6 on WinXP. Did you fix it? Are you sure they are not working for you?

Make sure you don't have scripting disabled on your Internet Explorer

I'm so stupid; the security level in my IE was set to "high".

I don't use IE for browsing, so this was probably set by SP. I guess that this might be the situation with other surfers too. If its not to much out of the scope of this page, is there any way to check the level of security in the visitor's IE using PHP, and to warn him to change it?

Thanks again for your help!

Instead of having a PHP and a HTC file AND loosing (minimal) resources by the server I suggest to make it this way:
(usually I only need 1 HTC file to solve my problem, and this use less resource and this cause less security holes because of this is standalone, no need to pass any parameters and/or files)
[Copy here the orginal HTC file content]
header("Content-type: text/x-component");
header("Content-Length: ".ob_get_length());
header("Content-Disposition: inline;");

I was able to get your drop-down menu working. However, I cant seem to get the drop-down to work on IE XP.


I'm still experiencing problems with the csshover. I have wrapped the file in a php file like you said. I have lowered my security settings so that I was able to get your drop-down menu working. However, I cant seem to get the drop-down to work on IE XP.

any suggestions would be greatlt appreciated.
Thank you, Trev

I’m as big a pusher of standards (and firefox ;-) as they come, but in a commercial situation where you’ve got a CMS built for IE6 only, written mostly with .HTC files, this WAS really important. For some of us it’s got to do with money and functionality, not design. In my opinion Microsoft stuffed up by burning the very people they enticed into their new technology years ago.

So thanks a lot for the info - much appreciated.

IE7 no longer uses HTCs. It is now a pure JavaScript solution. Some developers did not have access to their servers and could not make the necessary configurations there.

Both 'sensible' applications of using HTC were made redundant by IE7 anyway; IE7 displays PNG transparencies just fine, and has decent support for css :hover.

This just saved my ass, thanks!


Thank you for this life saving script!

And by the way, do you have a copy of the HTC file you used? What the HTC file specific to this use of wrapping it in a PHP file or is it the same file that Peter came up with?


John Maven

I am still not able to get my navigation to work in IE 6 on Windows XP using this solution.
Could someone take a look at this page and let me know if you can see the problem?
My page

Nevermind. It was just a php issue. Works great. Thanks!