使网站适合移动设备
有没有办法做到这一点,以便当使用手机或其他小型移动设备查看网站时,该网站会自动识别正在查看该网站,并重定向到手机友好的子域镜像或自动调用一个脚本,该脚本使它对电话友好吗?
任何文章或建议将不胜感激!
Is there a way to make it so when a site is viewed with a phone or other small mobile device the site automatically recognizes that it is being viewed as such and either re-directs to a phone friendly subdomain mirror or automatically calls a script that makes it phone friendly?
Any articles or advice would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
HTTP 请求中的
user-agent
可以帮助检测浏览器。然后,当从特定浏览器查看页面时,您可以重定向到子域。否则,
media
CSS也可以使用选择器来使布局适应设备的类型。有媒体类型handheld
,但我不知道它的支持程度如何。The
user-agent
in the HTTP request can help detect the browser. You can then redirect to the subdomain when the page is viewed from specific browsers.Otherwise, the
media
CSS selector can be used as well to adapt the layout to the kind of device. There is media typehandheld
, but I don't know how well it is supported.使用多个 CSS。
Use multiple CSS.
当然,您可以使用 JavaScript 代码来检查用户运行的浏览器类型,并对此做出适当的响应。例如:
参考:http://www.w3schools.com/js/js_browser.asp
Well, certainly you can use JavaScript code to check what kind of browsers that the users run, and respond appropiately to that. For example :
Reference : http://www.w3schools.com/js/js_browser.asp
有多种方法可以帮助您检测移动浏览器。以下是一些示例 PHP 代码:
来源: http://www.brainhandles.com/技术思想/检测移动浏览器
There are several methods that can help you detect mobile browsers. Here's some sample PHP code:
Source: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers