I'm trying to check if a person is using anything IE with version less than 8 or anything else.
I use conditional comments to declare boolean..
<!--[if lt IE 8]>
<script type="text/javascript">var badIE = true;</script>
<![endif]-->
And now I check in my js file the boolean like this:
if (badIE == true){
alert('You have bad IE!');
} else {
alert('Bueno!');
}
If I use IE7 or IE6, it alerts that "You have bad IE!". If I use anything else, it should alert "Bueno!", but it does not. What is the problem?
You need to declare the badIE
variable as false first in order for it to work, or else the code outside of the conditional knows nothing about badIE
Try this:
<script>
var badIE = false;
</script>
<!--[if lt IE 8]>
<script type="text/javascript">badIE = true;</script>
<![endif]-->
<script>
if (badIE == true){
alert('You have bad IE!');
} else {
alert('Bueno!');
}
</script>
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