/* * jQuery Browser Detect */ //Script para comprobar rutas de ficheros fisicos. function file_exists (url) { var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); if (!req) { throw new Error('XMLHttpRequest not supported'); } req.open('HEAD', url, false); req.send(null); if (req.status == 200){ return true; } return false; } //Especificamos a jQuery los navegadores Util para diferenciar Safari de Chrome). var userAgent = navigator.userAgent.toLowerCase(); jQuery.browser = { version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1], chrome: /chrome/.test( userAgent ), safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ), opera: /opera/.test( userAgent ), msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ), mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) }; //Ejecutamos las condiciones si el fichero existe o no. jQuery(document).ready(function($){ var WMB_URL_CSS = '/sites/all/themes/wmb/css/browser/'; jQuery.each(jQuery.browser, function(i, val) { if(file_exists(WMB_URL_CSS + "ie9.css") ){ if(i=="msie" && jQuery.browser.version.substr(0,3)=="9.0"){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'ie9.css" type="text/css" />'); } } if(file_exists(WMB_URL_CSS + "ie8.css") ){ if(i=="msie" && jQuery.browser.version.substr(0,3)=="8.0"){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'ie8.css" type="text/css" />'); } } if (file_exists(WMB_URL_CSS + "ie7.css")){ if(i=="msie" && jQuery.browser.version.substr(0,3)=="7.0"){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'ie7.css" type="text/css" />'); } } if (file_exists(WMB_URL_CSS + "ie6.css")){ if(i=="msie" && jQuery.browser.version.substr(0,3)=="6.0"){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'ie6.css" type="text/css" />'); } } if (file_exists(WMB_URL_CSS + "mozilla.css")){ if($.browser.mozilla){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'mozilla.css" type="text/css" />'); } } if (file_exists(WMB_URL_CSS + "opera.css")){ if($.browser.opera){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'opera.css" type="text/css" />'); } } if (file_exists(WMB_URL_CSS + "safari.css")){ if($.browser.safari){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'safari.css" type="text/css" />'); } } if (file_exists(WMB_URL_CSS + "chrome.css")){ if($.browser.chrome){ $('head').append('<link rel="stylesheet" href="'+WMB_URL_CSS+'chrome.css" type="text/css" />'); } } }); });
sábado, 18 de mayo de 2013
Detectar navegador con jQuery
Si se desea detectar navegador con jQuery, pdemos usar la siguiente script.
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario