Hi, anyone know if there’s a way to detect if the web application is running within a desktop browser and not a mobile one? Thanks, Dave.
If your purposes are for layout, you can check Session.ClientWidth
and determine if it’s skinny enough for a mobile layout.
One of the reasons Tim, but others too. But this may be a good enough workaround for my purposes, thank you.
It reports: Chrome 119.0.0.0 on OS X 10.15.7 64-bit
Running: Chrome 119.0.6045.199, macOS 13.6.1
same here
platform.js detects the right browser, but macos 10.15.7 instead of ventura …
Right, Apple (and others) do things to make detecting the platform intentionally difficult. You should not be doing that. You may know the size of the view for the purposes of layout, but anything else isn’t warranted for the web. That is why I worded my response the way I did.
Yes, this is not a perfect solution. I used examples from: https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browsers
For me it shows:
Chrome 119.0.0.0 on Windows 10 64-bit
and it is:
Chrome 119.0.6045.199 on Windows 10 64-bit
EDIT: I have another version if anyone is interested
Ideally (but really thinking its probably not possible) - I was hoping for a .isDesktop or .isMobile type property somewhere i.e. making an absolute distinction as to what platform the app is being viewed on. But, Tim is right, if it ain’t wide enough to display the content, then that’s good enough.
It is widely regarded that knowing the specific platform leads to involuntary user tracking which is why iOS as a whole and Safari will lie about what platform and version they are.
I just had a look at the connection logs from my WebApp (more than 1 million sessions in the past year).
Session.Platform
is a good way to detect Desktop or Mobile.
The possible values (logged so far) for Session.Platform are:
Session.Platform | Count |
---|---|
“” (empty) | 25 |
ARM | 2 |
iPad | 2013 |
iPhone | 649103 |
iPod touch | 4 |
Linux aarch64 | 67041 |
Linux armv7l | 8028 |
Linux armv81 | 88850 |
Linux armv8l | 86069 |
Linux i686 | 87 |
Linux x86_64 | 2538 |
MacIntel | 34606 |
OpenBSD amd64 | 1 |
Win32 | 65630 |
Win64 | 1 |
Then, as Tim suggested, check the Session.ClientWidth
and Session.ClientHeight
.
If height > width you can assume it is a Mobile, unless the Session.Platform
is MacIntel, Win32, Win64
Also, it is up to you to decide if iPad is a desktop or mobile device.
You really can’t make that assumption these days. You can run iOS apps now on a desktop. You can run an iPad app in various split view formats in which case the screen size is more like a phone, etc.
The advice given previously is solid: detect the features that you care about, and only those features. Don’t make assumptions based on the platform or. device.
Actually I can make that assumption.
I never said that if width > height
Desktop should be assumed. That is in fact the tricky part, as the device could be in landscape.
If Session.ClientHeight > Session.ClientWidth and _
Session.Platform <> "MacIntel" and _
Session.Platform <> "Win32" and _
Session.Platform <> "Win64" and _
Session.ClientWidth < 1000 then
//Most likely Mobile
Elseif Session.Platform = "MacIntel" or _
Session.Platform = "Win32" or _
Session.Platform = "Win64" then
//Desktop
Else
//This is where it is tricky
End If