I would like to change a line of my javascript code based on whether the browser is IE7 or not. Here is the code for any other browser:
function showHint(myId)
{
document.getElementById(myId).style.display = "inline-block";
}
For IE7, I want display = "inline".
I've made an attempt at conditional compilation (this showed me how to detect the browser), but it didn't work:
function showHint(myId)
{
document.getElementById(myId).style.display = "inline-block";
/*@cc_on
@if(navigator.appVersion.indexOf(“MSIE 7.”)!=-1)
{
document.getElementById(myId).style.display = "inline";
}
@*/
}
Any help is greatly appreciated!
EDIT: I'm not using JQuery.
Set a global determined by the behavior of IE's conditional comment parsing:
<!--[if IE 7]><script> var isIE7 = true; </script><![endif]-->
You need to check navigator.userAgent.
If you use jQuery, you can simply write
if ($.browser.msie && $.browser.version === 7)
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