Is there a way to do have only one line of IE specific javascript.
<script>
<!--[if gte IE 7]><!-->SOME IE JS<![endif]-->
<!--[else]><!-->NORMAL JS<![endif]-->
</script>
Option 1
Similar to the code in your original question, but with the conditions in the proper location - outside the script block:
<!--[if lt IE 7]>
<script type="text/javascript">
//Your one line of code
</script>
<![endif]-->
<script type="text/javascript">
//All other script
</script>
Option 2
Use browser detection to check the browser and version. I recommend http://www.quirksmode.org/js/detect.html. If you used the .js file found at the link, you could so something like this:
<script type="text/javascript">
if(BrowserDetect.browser == "Explorer" && BrowserDetect.version == 7) {
//IE 7
}
else {
//All others
}
</script>
You could define a global var in an <!--[if... and then just check for it later.
<!--[if lt IE 7]>
<script type="text/javascript">
old_ie = true;
</script>
<![endif]-->
...
if (old_ie)
//whatever you need to do
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With