ioos / sanctuarywatch

WordPress documentation and plug-ins for the National Marine Santuaries web-enabled Condition Reporting (WebCR) website sanctuarywatch.ioos.us.
MIT License
1 stars 0 forks source link

Webpage Rendering Based on Device Type/OS #7

Closed skanda-vasishta closed 1 month ago

skanda-vasishta commented 2 months ago

There are three possible ways to access the website that we will focus on:

Ideally, look at device OS (can infer touchscreen if OS is iOS or Android), then go from there.

skanda-vasishta commented 2 months ago

From Jai:

If we are running on an ipad, a tablet-based Android device, or a Chromebook, we want the animated icons to fire. How would you know? Check this list of user agents as an example: https://deviceatlas.com/blog/list-of-user-agent-strings

Chromebooks show up as CrOS. You can check on the user agents whether the client is running android or ios - which doesn't really distinguish between tablets or mobile devices. For that, we can use the clientWidth property, where smaller widths will switch over to mobile mode. Here we would need to get the clientwidth of the root element. https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth

We can use the ontouchstart event in javascript to detect for touch sensitive chromebooks or touch sensitive windows tablets. https://www.geeksforgeeks.org/how-to-detect-touch-screen-device-using-javascript/