What's the best way to detect a user playing on PC or Mobile?

There’s a lot of conflicting answers but one that I’m more drawn to is the canvas / device size. Any suggestions?

Cross-browser @media (width) and @media (height) values

var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);

There are really a lot of opinions but this seems quite accurate across different browsers and platforms. See hot discussion in details - Get the browser viewport dimensions with JavaScript - Stack Overflow

hello there! any luck on this issue?
which is nowadays to detect if user is on mobile or pc?

I’m having to much differences with camera.wheelPrecision
i would like to set up one for computers and another for mobiles :slight_smile:

One may use detect-gpu - npm

2 Likes

What about the navigator user agent? I believe this still works (didn’t try lately)

////// DETECT MOBILE /////////

var createIsMobile = function() {

if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
//make mobile controls
console.log(“hello mobile”);

var tx = new BABYLON.GUI.TextBlock();
tx.color = “black”;
tx.text = “This is mobile!”
tx.fontSize = “96px”;

advancedTexture.addControl(tx);
// gui.domElement.style.display = “none”;

}

else {
//desktop gui
console.log (“is desktop”);
//gui.domElement.style.display = “none”;
}

};

Hey, I personally check for the ontouchstart method like that:
const isTouchDevice = () => "ontouchstart" in window;
But I’ve found something like this on the Internet

3 Likes

Oh, through the touch, not a bad idea. :smiley: That little piece of script also looks nice. Might be worth checking it out. I’m gonna keep this bookmarked for later, just in case.