0

I have this code:

$(document).ready(function () {
    $('body a[href]').qtip({
        hide: {
            fixed: true,
            delay: 500
        },
        style: {
            classes: 'qtip-dark qtip-shadow'
        },
        position: {
            viewport: $(window)
        }
    });
    jQuery.each(jQuery.browser, function (i, val) {
        $("<div>" + i + " : <span>" + val + "</span>")
            .appendTo(document.body);
    });
});

In addition to the above code, how would I run a script ONLY if internet explorer is detected from this browser function? The script i want to run if internet explorer is detected is:

$(document).ready(function () {
    $('body a[href]').qtip({
        hide: {
            fixed: true,
            delay: 500
        },
        style: {
            classes: 'qtip-dark qtip-shadow'
        }
    });
Igor Jerosimić
  • 13,621
  • 6
  • 44
  • 53
DBroncos1558
  • 141
  • 3
  • 10
  • 2
    note that browser-checking is quiet suboptimal.. as the API points this out too: Description: Contains flags for the useragent, read from navigator.userAgent. We recommend against using this property; please try to use feature detection instead (see jQuery.support). jQuery.browser may be moved to a plugin in a future release of jQuery. – El Hocko Mar 06 '13 at 18:28
  • 1
    Duplicate of http://stackoverflow.com/questions/4411551/if-browser-is-internet-explorer-run-an-alternative-script-instead – Chris.Stover Mar 06 '13 at 18:32
  • @Sirko [Read the docs](http://api.jquery.com/jQuery.browser/) -- `jQuery.browser` has been deprecated and, in 1.9, completely removed. – Blazemonger Mar 06 '13 at 18:34
  • I didnt see that duplicate, and for someone such as myself very new to jquery, etc.. that did not seem to help my specific problem. I apologize if I duplicated tho new to StackOverflow as well. Should I delete this post? – DBroncos1558 Mar 06 '13 at 18:38

2 Answers2

6

Use IE conditional comments.

<!--[if IE]>
<script>
// run code here or link to external file
</script>
<![endif]-->

They're highly customizable, too -- <!--[if lt IE 8]> will only run for IE 7 or below, for instance. Developers use this to create custom stylesheets for IE6/7/8 all the time.

That said, you should really consider using feature detection instead of browser detection for whatever you're trying to implement. See http://modernizr.com for what is arguably the best solution yet devised.

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
0

You can use javascript code to detect

//Test for Internet Explorer
if (/MSIE\s([\d.]+)/.test(navigator.userAgent)) {
    //Get the IE version.  This will be 6 for IE6, 7 for IE7, etc...
    version = new Number(RegExp.$1);
}
Shoaib Shaikh
  • 4,565
  • 1
  • 27
  • 35
  • *jQuery.browser* is deprecated since jQuery v1.3. And has been removed completely in v1.9. – Amy Mar 06 '13 at 18:34