我如何检测用户是否正在从移动网络浏览器浏览我的网站,以便我可以自动检测和显示我的网站的适当版本?


当前回答

在检测移动浏览器上有开源脚本,可以在Apache、ASP、ColdFusion、JavaScript和PHP中实现这一点。

其他回答

Just a thought but what if you worked this problem from the opposite direction? Rather than determining which browsers are mobile why not determine which browsers are not? Then code your site to default to the mobile version and redirect to the standard version. There are two basic possibilities when looking at a mobile browser. Either it has javascript support or it doesn't. So if the browser does not have javascript support it will default to the mobile version. If it does have JavaScript support, check the screen size. Anything below a certain size will likely also be a mobile browser. Anything larger will get redirected to your standard layout. Then all you need to do is determine if the user with JavaScript disabled is mobile or not. According to the W3C the number of users with JavaScript disabled was about 5% and of those users most have turned it off which implies that they actually know what they are doing with a browser. Are they a large part of your audience? If not then don't worry about them. If so, whats the worst case scenario? You have those users browsing the mobile version of your site, and that's a good thing.

在检测移动浏览器上有开源脚本,可以在Apache、ASP、ColdFusion、JavaScript和PHP中实现这一点。

移动设备浏览器文件是检测移动(和其他)ASP浏览器的好方法。NET项目:http://mdbf.codeplex.com/

以下是我如何在JavaScript中做到这一点:

function isMobile() {
  var index = navigator.appVersion.indexOf("Mobile");
  return (index > -1);
}

在www.tablemaker.net/test/mobile.html上可以看到一个例子,它把手机上的字体放大了三倍。

MobileESP有PHP, Java, APS。NET (c#), Ruby和JavaScript钩子。 它还拥有Apache 2许可证,因此可以免费用于商业用途。 对我来说,关键是它只识别浏览器和平台,而不识别屏幕大小和其他指标,这使它保持较小的规模。