Reputation: 7589
i'm having a finished website and need to optimize it for mobile devices (ipad/iphone/smartphones ..). what's the best way to detect which mobile device/browser is used? (eg. by jquery-plugin) thanks
Upvotes: 3
Views: 177
Reputation: 2759
You could tell the device between Android/iPad/iPhone/BlackBarry etc. using User-Agent in JavaScript or PHP. See this article: http://graphicmaniacs.com/note/detecting-iphone-ipod-ipad-android-and-blackberry-browser-with-javascript-and-php/
Upvotes: 0
Reputation: 11530
JavaScript/jQuery is not the best way at all; apart from iPhones etc remember there are also Nokias, and other non-smart phones, which may or may not run JavaScript at all, and if they do, it won't be particularly quickly. Attempting to reconfigure your site using JavaScript on a phone over a few years old is pretty much just going to freeze the phone for at least a second or two whenever a page loads.
I would strongly suggest you look into doing this on the server side as much as possible - even if it's as simple as just swapping the stylesheet. At the basic level you can check the User-Agent
header sent by the browser and work it out from there. In PHP, use the get_browser
function.
Upvotes: 2