Gardacus 2 Posted November 15, 2012 Report Share Posted November 15, 2012 Hi all I am not sure if this topic exists or where to place it, so please forgive me if I posted this on the wrong site. I am looking for a smart (PHP preferred) solution to redirect mobile devices to a mobile version of a website. At this moment this is my javascript solution, but it is not fool-proof: <script type="text/javascript"> if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('Blackberry') != -1) || (navigator.userAgent.indexOf('Opera Mini') != -1) || (navigator.userAgent.indexOf('WebKit') != -1)) { document.location ="mobile/index.html"; } </script> It works on the devices mentioned, but Safari on an iMac also is seen as a mobile device, and therefore redirected to the mobile site. Is there any smart solution for this that I can build in PHP? Thanks all! Mike Quote Link to post Share on other sites
Larry 428 Posted November 16, 2012 Report Share Posted November 16, 2012 You really don't want to code this yourself. Use this instead: http://detectmobilebrowsers.com/ 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.