Sto lavorando con dispositivo mobile con scanner incorporato. Per poter utilizzare la libreria JavaScript di diversi dispositivi e per evitare conflitti con quelle librerie di produttori diversi (Zebra, Honeywell, Datalogic, iOs ecc ...) ho bisogno di trovare un modo per identificare ogni dispositivo in modo che io possa caricare la libreria corretta e questo è quello che mi è venuto in mente. Godetevi
getDeviceName: function() {
var deviceName = '';
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
Datalogic: function() {
return navigator.userAgent.match(/DL-AXIS/i);
},
Bluebird: function() {
return navigator.userAgent.match(/EF500/i);
},
Honeywell: function() {
return navigator.userAgent.match(/CT50/i);
},
Zebra: function() {
return navigator.userAgent.match(/TC70|TC55/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Datalogic() || isMobile.Bluebird() || isMobile.Honeywell() || isMobile.Zebra() || isMobile.BlackBerry() || isMobile.Android() || isMobile.iOS() || isMobile.Windows());
}
};
if (isMobile.Datalogic())
deviceName = 'Datalogic';
else if (isMobile.Bluebird())
deviceName = 'Bluebird';
else if (isMobile.Honeywell())
deviceName = 'Honeywell';
else if (isMobile.Zebra())
deviceName = 'Zebra';
else if (isMobile.BlackBerry())
deviceName = 'BlackBerry';
else if (isMobile.iOS())
deviceName = 'iOS';
else if ((deviceName == '') && (isMobile.Android()))
deviceName = 'Android';
else if ((deviceName == '') && (isMobile.Windows()))
deviceName = 'Windows';
if (deviceName != '') {
consoleLog('Devices information deviceName = ' + deviceName);
consoleLog('Devices information any = ' + isMobile.any());
consoleLog('navigator.userAgent = ' + navigator.userAgent);
}
return deviceName;
},
e questo è un esempio di come può essere utilizzato:
initializeHandheldScanners: function() {
if (DeviceCtrl.getDeviceName() == 'Zebra')
DeviceCtrl.initializeSymbolScanner();
if (DeviceCtrl.getDeviceName() == 'Honeywell')
DeviceCtrl.initializeHoneywellScanner();
if (DeviceCtrl.getDeviceName() == 'Datalogic')
DeviceCtrl.initializeDatalogicScanner();
},
Si può dire grazie a Cory LaViska. L'ho fatto basandomi sul suo lavoro. Ecco il link se volete saperne di più
https://www.abeautifulsite.net/detecting-mobile-devices-with-javascript
dipende dal browser del dispositivo mobile è in esecuzione Ma vuoi sapere se si tratta di un iPhone o dispositivo Android o il cui nome esattamente cosa avete bisogno? –
L'unica cosa che puoi ottenere è User-Agent –
Ecco un link per usare 'WURFL.js', è gratuito http://www.smashingmagazine.com/2014/07/01/server-side-device-detection- with-javascript/ – Pierre