Home > Blockchain >  How do I get what kind of device who visits my website?
How do I get what kind of device who visits my website?

Time:02-20

I am making a JavaScript game but I want the canvas to be different sizes depending if it is for instance an iPhone who visits

const canvas = document.querySelector("canvas"); canvas.width = 500;

So my question is how do I get the device information?

CodePudding user response:

You can simply use the width and height property of the window.screen object

const width = screen.width;

const height = screen.height;

CodePudding user response:

What you are looking for is window.navigator.platform.

switch(window.navigator.platform) {
   case 'iPhone':
      // Set width for iPhones
      break;
   case 'Android':
      // Set width for Androids
      break;
   default:
      // Set width of other devices
      break;
}
  • Related