Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable script if user browsing using IE8

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

like image 827
johnathan Avatar asked Jul 20 '11 14:07

johnathan


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

like image 120
naveen Avatar answered Oct 09 '22 15:10

naveen


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.

like image 42
cdeszaq Avatar answered Oct 09 '22 15:10

cdeszaq


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

like image 1
sll Avatar answered Oct 09 '22 14:10

sll