There’s quite a few out there that try to do this, and they all fall victim to one thing: You can’t predict ALL the devices that are out there. So in order to only target mobile browsers, I stumbled on this great script from. So it was just safer to target ALL mobile browsers (so binary, black-and-whitey of me, I can’t even handle myself!) A media query could do it for most of the users out there, but I’m sure it would still fail 2-5% of the time for some mobile users. In my case I couldn’t worry about whether the user was on a really wide tablet to fit the content I was displaying. Those are important questions, so here’s what I did: 1) Targeting Mobile Devices Seems simple enough, right? Well… it’s a bit of a rabbit hole, it turns out. Here’s all the things you need to take into consideration:ġ) Are you really just wanting to target mobile devices, or just a max-screen-width? Because you could use media queries instead.Ģ) How are you going to test this? If you’re developing locally you can use browser testing tools like or whatnot.ģ) Are you really just wanting to affect one element for mobile browsers, or are you actually trying to remove a desktop element, and replace it with a mobile element? So I sought out a simple way to detect the user was on a mobile device, then swap out the class name of an element. They’re so small and have such unique needs sometimes, that you end up needing to do some very targeted things for them. You are coding some great theme or plugin and you get to a point where you realize that you want something to change ONLY for mobile devices. They’re so small and have such unique needs sometimes, that you end up needing to do some very targeted things for them.… Read more Detecting, Targeting, and Testing Mobile Devices with Javascript
0 Comments
Leave a Reply. |