I would probably use a comment hack with IE conditional comments to do the version detection.
It's technically not using javascript to do the detection and is rather using a feature inherent to IE but it should work more consistently than a complex javascript function.