php/jquery - Web 开发:移动设备
我有一个完成的网站,需要针对移动设备(ipad/iphone/智能手机..)进行优化。 检测使用哪种移动设备/浏览器的最佳方法是什么? (例如,通过 jquery-plugin) 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
最终幸福2024-12-01 22:29:13
您可以使用 JavaScript 或 PHP 中的用户代理来区分 Android/iPad/iPhone/BlackBarry 等设备。请参阅这篇文章: http://graphicmaniacs.com/note/detecting-iphone-ipod-ipad-android-and-blackberry-browser-with-javascript-and-php/
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
JavaScript/jQuery 根本不是最好的方法;除了 iPhone 等之外,请记住还有诺基亚和其他非智能手机,它们可能根本不运行 JavaScript,即使运行,也不会特别快。尝试在使用了几年的手机上使用 JavaScript 重新配置网站几乎只会在页面加载时使手机冻结至少一两秒。
我强烈建议您尽可能在服务器端执行此操作 - 即使它就像交换样式表一样简单。在基本级别上,您可以检查浏览器发送的
User-Agent
标头并从那里计算出来。在 PHP 中,使用get_browser
函数。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 theget_browser
function.