i want a javascript code to disable the script i made if the user is browsing using Internet explorer 8.
-
4Generally speaking "If using IE8" is a very poor decision point. What is the problem with 8 that you don't have with 7 or 9? Why can't you fix it? Why can't you test for the problem instead of the browser?Quentin– Quentin2011-07-20 14:43:09 +00:00Commented Jul 20, 2011 at 14:43
-
actually i want to disable the script for users using 8 and above. I have not problem with my script on IE7. If you can help me to disable it on all IE , i will really appreciate it. Thank youjohnathan– johnathan2011-07-20 14:45:18 +00:00Commented Jul 20, 2011 at 14:45
-
why disable? you should write javascript code that works on all major browsers and should work on ie8 / 9 tried it with jquery?user753676– user7536762011-07-20 15:05:11 +00:00Commented Jul 20, 2011 at 15:05
3 Answers
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'?
2 Comments
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.
Comments
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