Option 1
Similar to the code in the original question, but with the conditions in the right place - outside the script block:
<script type="text/javascript"> </script>
Option 2
Use browser detection to check browser and version. I recommend http://www.quirksmode.org/js/detect.html . If you used the .js file found from the link, you could have something like this:
<script type="text/javascript"> if(BrowserDetect.browser == "Explorer" && BrowserDetect.version == 7) { </script>
source share