Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect "request desktop site" mode of iOS Mobile Safari and Chrome?

I'd like to send iPad version of my web site when users use "request desktop site" of iOS mobile safari or "request desktop version" of iOS Chrome. It seems that only user-agent is different in that mode, and it seems impossible to detect. Any ideas?

My site has three versions : desktop / tablet / smartphone. The tablet version is a static version of desktop version which is very dynamic and uses JavaScript heavily (parallax effects.)

like image 584
apptaro Avatar asked May 15 '15 04:05

apptaro


2 Answers

Please see the answer to this question: https://stackoverflow.com/a/58064481/1237536

it works flawlessly (for now, anyway)..

Basically, when iPads are in 'Desktop mode', they advertise themselves as MacIntel, but no Mac currently has a touchscreen, so you look for a MacIntel with touch enabled:

let isIOS = /iPad|iPhone|iPod/.test(navigator.platform) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)

but you should definitely look at the original answer -- i'm not trying to take credit: https://stackoverflow.com/a/58064481/1237536

like image 66
Peter Avatar answered Sep 17 '22 20:09

Peter


Another dirty hack is to use platform.maxTouchPoints on iOS 13+. This field is still present even after requesting the desktop version, but on real desktop Safari this field is absent.

like image 34
Дмитрий Ляпунов Avatar answered Sep 19 '22 20:09

Дмитрий Ляпунов