5

i want a javascript code to disable the script i made if the user is browsing using Internet explorer 8.

3
  • 4
    Generally 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? Commented 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 you Commented 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? Commented Jul 20, 2011 at 15:05

3 Answers 3

12

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'?

Sign up to request clarification or add additional context in comments.

2 Comments

in the "path/to/external/script" i will replace it with the external javascript file i want to disable right? What i must add to " // your inline script goes here" ?? I want just to disable the script on IE8
This disable the call in other browsers than IE8+, so it won't work for chrome nor firefox:(
2

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

1

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

9 Comments

Just a link === Not an answer
@Wesley Murch: Hey, I wont copy paste content across a intrawebs, the hyperlink specially designed for this purposes. Sometimes hyperlink to a good solution better than posting ugly code or copy paste thm without whole article notes which could be vital, so I'm not sure whether you're right when downvoting my answer
See here: en.wikipedia.org/wiki/Link_rot and here Are answers that just contain links elsewhere really "good answers"? and here Why is linking bad? Adding at least some context to your answer is perfectly fine, especially if you attribute the source as you are doing.
Thanks for the links, I'll read and than reconsider my point of view
The only problem with this solution is that all browsers are penalized because they all will have to run that javascript to determine if they are IE8. People using well behaved browsers (I'm assuming IE8 is not well behaved which is why the other script needs to be deactivated) should not be penalized for IE8 behaving poorly.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.