i want a javascript code to disable the script i made if the user is browsing using Internet explorer 8.
Try this.
For disabling script for IE 8
<!--[if !(IE 8)]><!-->
<script src="path/to/external/script"></script>
<script>
// your inline script goes here
</script>
<!--<![endif]-->
For disabling script for IE 8 and above
<!--[if !(gte IE 8)]><!-->
<script src="path/to/external/script"></script>
<script>
// your inline script goes here
</script>
<!--<![endif]-->
Read bobince's answer: Conditional comment for 'Except IE8'?
One way to do this would be to use another script, enclosed in IE-specific conditional comments, to deactivate the first one. Of course, this means you need to have some way to deactivate the 1st one, but that's not an IE-specific issue.
Something like this:
<!--[if (gte IE 8) ]><script>deactivate1stScript();</script><![endif]-->
By using the conditional comments, you are letting IE do the work, and no other browser will have to process any extra JavaScript because only IE will pay attention to the code in the comments (and IE8 specifically)
However, I do agree with @Quentin that targeting specific browsers is usually not the best idea. If there is certain functionality that your script needs, such as Canvas or SVG support, using a feature-detection library such as Modernizr is a much better way to deal with this.
See very straightforward solution here How to detect IE8 using JavaScript
The main idea is to run javascript functuion which return version of a current browser and than construct your script usng conditional statements like if, switch
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