Do not try to detect if your device is mobile or desktop via browser, this is less reliable than checking for majority in porn site entry. Chrome itself mobile has an option to pass through Chrome desktop, and it’s not even an advanced option. It’s in the application’s basic menu.
If you try to determine if a device is mobile by user agent browser, the only thing you will guarantee is that new mobile browsers will not receive the mobile experience when accessing your website.
If you try to determine if the device is a mobile phone by its capabilities (i.e.: detect if the device supports touch), you will get bizarre results. My laptop, for example, is touch sensitive. Imagine a site with a mobile layout rendered on a screen of 15". That’s when I don’t plug it into television...
The correct way to develop pages is to be agnostic about the type of device. Serve layout based on resolution, but so it automatically fits to the window without having to reload the page. This is possible with bootstrap, for example, so I recommend it.
Regarding Javascript, detecting if the browser is mobile is an even worse practice. Just because certain functionality has problems in a cell phone model does not mean that it will have the same problems in another model, and vice versa. So either you deprive all users of current mobile browsers of something that would be interesting, or you serve potentially broken functionality for everyone. It is best to determine which javascript features to serve based on the device’s capabilities, not based on the browser name. There are libraries that help a lot in this. I recommend modernize.
Are you using any CSS framework?
– Simão Ítalo
If not, take a look at CSS media queries that can help you.
– Simão Ítalo
This article may help you http://www.devmedia.com.br/utilizando-css-media-queries/27085 Explain how it works
– A.L Freire
I would love that if it existed, but unfortunately the committees that standardize the web are so bad, that there is no simple way. Everything is very full of details, and it’s not 100% as it should be. But there are these twig breaks as media-queries, which are still a pig patch, but it’s better than nothing. And I am giving +1 in your question, because it is a valid doubt, although I do not have an answer that will solve well currently.
– Bacco
I have little experience, but ... if you give a
debug($_SERVER);
and check the'HTTP_USER_AGENT'
, won’t be able to verify the type of system the site is running on? Output example:'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0',
, then it is a systemUbuntu
. Resurrecting Post...– Marcos Henzel