我有一个JavaScript代码重定向手机用户。你可以检查代码,我从网上捡起来,总newb,我会重视你对脚本质量的输入...Javascript代码重定向手机用户
它是否涵盖所有类型的手机?
function RedirectSmartphone(url) {
if (url && url.length > 0 && IsSmartphone())
window.location = url;
}
function IsSmartphone() {
if (DetectUagent("android")) return true;
else if (DetectUagent("iphone")) return true;
else if (DetectUagent("ipod")) return true;
else if (DetectUagent("symbian")) return true;
return false;
}
function DetectUagent(name) {
var uagent = navigator.userAgent.toLowerCase();
if (uagent.search(name) > -1)
return true;
else
return false;
}
RedirectSmartphone("http://mobile.version.com");
http://detectmobilebrowser.com/将为您生成代码,如果你想。我以前使用过他们的代码,它工作得很好。 – dtanders
我不知道。我个人会检查屏幕分辨率,而不是嗅探用户代理。这样你就可以在不同的屏幕上显示正确的页面/样式。 –
是否涵盖所有类型的手机? **否。**关于黑莓,WebOS和Windows Phone 7(仅举几例)? – Greg