Ejemplo 1: dispositivo de obtención de javascript
window.navigator.userAgent
Ejemplo 2: dispositivo de detección de js
agent =browser:name:null,version:null,v:null,userAgent:null,app:null,os:null,mobile:false,pointlock:false;var nVer =navigator.appVersion;var nAgt =navigator.userAgent;var browserName =navigator.appName;var fullVersion =''+parseFloat(navigator.appVersion);var majorVersion =parseInt(navigator.appVersion,10);var nameOffset,verOffset,ix;
agent.pointlock='pointerLockElement'indocument||'mozPointerLockElement'indocument||'webkitPointerLockElement'indocument;// In Opera, the true version is after "Opera" or after "Version"if((verOffset=nAgt.indexOf("Opera"))!=-1)
browserName ="Opera";
fullVersion = nAgt.substring(verOffset+6);if((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);// In MSIE, the true version is after "MSIE" in userAgentelseif((verOffset=nAgt.indexOf("MSIE"))!=-1)
browserName ="Microsoft Internet Explorer";
fullVersion = nAgt.substring(verOffset+5);// In Chrome, the true version is after "Chrome" elseif((verOffset=nAgt.indexOf("Chrome"))!=-1)
browserName ="Chrome";
fullVersion = nAgt.substring(verOffset+7);// In Safari, the true version is after "Safari" or after "Version" elseif((verOffset=nAgt.indexOf("Safari"))!=-1)
browserName ="Safari";
fullVersion = nAgt.substring(verOffset+7);if((verOffset=nAgt.indexOf("Version"))!=-1)
fullVersion = nAgt.substring(verOffset+8);// In Firefox, the true version is after "Firefox" elseif((verOffset=nAgt.indexOf("Firefox"))!=-1)
browserName ="Firefox";
fullVersion = nAgt.substring(verOffset+8);// In most other browsers, "name/version" is at the end of userAgent elseif((nameOffset=nAgt.lastIndexOf(' ')+1)<(verOffset=nAgt.lastIndexOf('/')))
browserName = nAgt.substring(nameOffset,verOffset);
fullVersion = nAgt.substring(verOffset+1);if(browserName.toLowerCase()==browserName.toUpperCase())
browserName =navigator.appName;// trim the fullVersion string at semicolon/space if presentif((ix=fullVersion.indexOf(";"))!=-1)
fullVersion=fullVersion.substring(0,ix);if((ix=fullVersion.indexOf(" "))!=-1)
fullVersion=fullVersion.substring(0,ix);
majorVersion =parseInt(''+fullVersion,10);if(isNaN(majorVersion))
fullVersion =''+parseFloat(navigator.appVersion);
majorVersion =parseInt(navigator.appVersion,10);
agent.browser.name= browserName;
agent.browser.version= fullVersion;
agent.browser.v= majorVersion;
agent.browser.app=navigator.appName;
agent.browser.userAgent=navigator.userAgent;varOSName="Unknown OS";if(navigator.appVersion.indexOf("Win")!=-1)OSName="Windows";if(navigator.appVersion.indexOf("Mac")!=-1)OSName="MacOS";if(navigator.appVersion.indexOf("X11")!=-1)OSName="UNIX";if(navigator.appVersion.indexOf("Linux")!=-1)OSName="Linux";
agent.browser.os=OSName;
agent.mobile=(typeofwindow.orientation!=="undefined")||(navigator.userAgent.indexOf('IEMobile')!==-1);
Comentarios y calificaciones del tutorial
Te invitamos a animar nuestra función ejecutando un comentario y dejando una puntuación te damos las gracias.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)