2

So I have a javascript function that runs on clicking a link in the site.

$('.mainNavWrap .preloadNav a, .bannerNav li a').click(function(event){
    event.preventDefault();
    linkLocation = this.href;
    $('.preloader2').fadeIn(100, redirectPage);
});
function redirectPage() {
    setTimeout(function(){
        window.location = linkLocation;
    }, 1000);

}

The function calls a preloader before the page redirects. How can I disable this entire function for ie8?

Kunj
  • 1,980
  • 2
  • 22
  • 34
YeahMKD
  • 415
  • 1
  • 6
  • 22
  • 1
    check this http://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie – Anoop Joshi P Jun 17 '14 at 04:10
  • http://stackoverflow.com/questions/5505155/how-not-to-load-a-script-in-ie – Arun P Johny Jun 17 '14 at 04:20
  • 1
    @AnoopJoshi is right, just the same question. Detect user-agent and check with a regex if is in certain range. Btw there is a more spesific navigator object http://www.quirksmode.org/js/detect.html reference – Marcos Eusebi Jun 17 '14 at 04:35

5 Answers5

2

May be you can try this:

        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");
        if (msie > 0)
        {
           /* CODING SPECIFIC TO IE BROWSER */
           if (parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))) == 8)
           {   /* CODING SPECIFIC TO IE8*/}
        }   
        else                 
        {
             /* CODING FOR OTHER BROWSERS*/
         }
    }
ngrashia
  • 9,869
  • 5
  • 43
  • 58
0

Method I

if ( $.browser.msie ) $('.preloader2').fadeIn(100, redirectPage);

Note: This will not work in jQuery 1.9 or later unless the jQuery Migrate plugin is included.

Method II

(Detect IE version (prior to v9) in JavaScript)

Add it in html:

<!doctype html>
<!--[if IE 8 ]>    <html class="ie8"> <![endif]-->

then use it in your script:

if ($('html').is('.ie8')) $('.preloader2').fadeIn(100, redirectPage);
Kunj
  • 1,980
  • 2
  • 22
  • 34
0

Check for SVG support coz ie8 doesnot support ie8 following is the code:-

 if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
 if (!document.createElement('SVG').getAttributeNS) {
     if (document.createElement('DATA').getAttributeNS) {
       //the browser is defently IE8
         return;
      }
   }
}
else
{
//call your function
}

or another way is:- function for checking ie8

function isIE () 
{
  var myNav = navigator.userAgent.toLowerCase();
  return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;
 }

 if (isIE () == 8) {
  // IE8 code
 } else {
   // Other versions IE or not IE
  }
pareshm
  • 4,874
  • 5
  • 35
  • 53
-1

Have it return false if the user agent matches IE8. Usually browser sniffing is not suggested, but it's pretty much the only way without hitting more browsers than necessary.

Here's a list of UA strings

  function redirectPage() {
        var ie = (navigator.userAgent.match(/(MSIE)/g) ? true : false );
       if (ie == true) {
    return false; // or browser-specific code
    } else {
        setTimeout(function(){
            window.location = linkLocation;
        }, 1000);
    }
    }

Wrote this from mobile, so pardon the formatting.

Eric Lagergren
  • 501
  • 2
  • 7
  • 18
-2

jQuery has functionality for seeing if a browser is any form of MSIE

if (!$.browser.msie) {
   // jquery function
}
Jatin
  • 3,065
  • 6
  • 28
  • 42