Distinguish Chrome from Safari using jQuery.browser

后端 未结 7 912
谎友^
谎友^ 2020-11-27 16:30

It seems jQuery.browser is able to identify webkit rather easily as of 1.4. But how can I use it to distinguish Chrome from Safari (and visa-versa)?

7条回答
  •  一生所求
    2020-11-27 16:56

    You can do like:

    // Is this a version of Chrome?
    if($.browser.chrome){
      userAgent = userAgent.substring(userAgent.indexOf('chrome/') +7);
      userAgent = userAgent.substring(0,userAgent.indexOf('.'));
      version = userAgent;
      // If it is chrome then jQuery thinks it's safari so we have to tell it it isn't
      $.browser.safari = false;
    }
    
    // Is this a version of Safari?
    
    if($.browser.safari){
      userAgent = userAgent.substring(userAgent.indexOf('safari/') +7);
      userAgent = userAgent.substring(0,userAgent.indexOf('.'));
      version = userAgent;
    }
    

    http://api.jquery.com/jQuery.browser/

提交回复
热议问题