0

I would like the following code to run on all browsers except IE (every version).

$('#divid a').click(function(e) {
   e.preventDefault();
});

I tried a few things from Stack but with no success.

like:

    <![if ! IE]>

    <script>
        $('#divid a').click(function(e) {
            e.preventDefault();
        });

    </script>

    <![endif]>
Marius S
  • 267
  • 3
  • 21
  • take a look at this question => http://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie – Amin Jafari Sep 30 '14 at 20:38
  • 1
    Why do you need this to not run in IE? is it because you want to do something special for IE, or is it just because IE just so happens to not support something this function does. If it's the latter, you are going about this all wrong. – Kevin B Sep 30 '14 at 21:02

3 Answers3

0

that should work , make sure that this is AFTER the other code that is to run in all browsers

<!--[if IE]>
    $(function(){
     $('#divid a').off();
    });
<![endif]-->

all that your code was doing was essentially checking is browser is IE then adding another click event which does nothing. use .off()

Scott Selby
  • 9,420
  • 12
  • 57
  • 96
0

If you're not to be dissuaded, at some other part of your app, include this:

window.checkIsIE = navigator.userAgent.indexOf('MSIE') != -1;

You can now refer to "checkIsIE" as a Boolean variable that indicates whether the user is using IE.

Unclean and lazy? Yes; so is the fundamentals of what you're doing. In all honesty, I can't deny that even my own work has resulted in problems that can't be solved in the clean way, but please be reminded that the clean way is to check whether the browser in question supports the features you need from it. There are even frameworks that can help you determine if certain CSS features are supported (Modernizr comes to mind).

The above code does not detect IE 11 - and I consider that a plus, since a good solid bet says that whatever strange, old-IE bug you're trying to circumvent does not occur in IE11.

Katana314
  • 8,429
  • 2
  • 28
  • 36
  • Thank you. The problem with my Jquery is that it's a very complex code and even toggles seem not to work. The bug also occurs in IE11. check this link on IE11. Try to select some text and then try to click on existing orange words. http://withcommentary.com/?bookid=11&chapter=21&quote=106 – Marius S Sep 30 '14 at 23:22
  • In that case, in the interest of fixing your issue, replace "MSIE" with "Trident" (IE's rendering engine). I'd really encourage you to figure out what on earth you're doing incorrectly in your own code though. It seems like some really bad mis-use of innerHTML. – Katana314 Oct 01 '14 at 14:26
  • I am willing to pay someone to fix the errors. let me know if you are interested. – Marius S Oct 01 '14 at 15:47
-1

jQuery has $.browser object, see the documentation

this might help you

if(! $.browser.msie ) { $('#divid a').click(function(e) { e.preventDefault(); }); }

Vahe Shadunts
  • 1,956
  • 14
  • 18
  • No it doesn't, see the documentation. "This property was removed in jQuery 1.9" – Kevin B Sep 30 '14 at 20:55
  • oh sorry @KevinB , I always using this, and haven't noticed about removing this functionality, however, es still can use this, because there are jQuery.migrate plugin :) – Vahe Shadunts Sep 30 '14 at 21:00
  • I know this functionality was removed. Don't worry, i tried multiple things from google before posting here – Marius S Sep 30 '14 at 21:07