如何在 Angular 项目中获取手机、平板或 PC 上的操作系统版本/名称

问题描述 投票:0回答:1

我在我的项目中使用 Angular 9,我需要获取设备信息,例如操作系统名称和版本...等等

现在我正在使用 ngx-device-detector 但不能在 8 及以下或 10 和 ios mobile 等 android 版本中工作以获取 os 版本

angular operating-system device detection info
1个回答
1
投票

您可以在AndroidiOSWindows中完美地使用angular-device-information

它对我的工作
 console.log(deviceInformationService.isMobile());  // returns if the device is a mobile device (android / iPhone / windows-phone etc)
  console.log(deviceInformationService.isTablet());  // returns if the device is a tablet (tablet iPad etc)
  console.log(deviceInformationService.isDesktop()); // returns if the app is running on a Desktop browser.
  console.log(deviceInformationService.getDeviceType()); // returns if the app is running on a Desktop browser.
  console.log(deviceInformationService.getDeviceInfo().os);  // returns os name like Windows/Android/iOS/Linux/Mac OS X etc
  console.log(deviceInformationService.getDeviceInfo().osVersion);  // returns os version like 10/8.1/7 ...etc
  console.log(deviceInformationService.getDeviceInfo().browser);  // returns browser name like chrome/firefox ...etc
  console.log(deviceInformationService.getDeviceInfo().browserVersion);  // returns browser version as number
  console.log(deviceInformationService.getDeviceInfo().browserMajorVersion);  // returns full browser version as number
  console.log(deviceInformationService.getDeviceInfo().screen_resolution);  // returns screen size like 1390x860/640x800 ...etc
  console.log(deviceInformationService.getDeviceInfo().cookies);  // returns cookies enabled or not
  console.log(deviceInformationService.getDeviceInfo().userAgent);  // returns userAgent
© www.soinside.com 2019 - 2024. All rights reserved.