代码自动检查设备类型,识别安卓、IOS等系统,然后跳转到不同的网址。
此实现方式是最基本的,简单易懂,仅供参考。
完整代码:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>客户端下载</title>
<script type="text/javascript">
function checkOS() {
//默认的地址
var defaultUrl = 'http://X/X.apk';
//如果检测到是Android系统需要跳转的地址
var androidUrl = 'http://X/X.apk'';
//如果检测到是iphone/ipod需要跳转的地址
var iphoneUrl = 'http://X/X.apk'';
//symbian跳转地址
var symbianUrl = 'http://X/X.apk'';
//windows phone跳转地址
var windowsPhoneUrl = 'http://X/X.apk'';
var url = '';
var ua = (navigator.userAgent || navigator.vendor || window.opera);
if (ua!=null) {
var uaName = ua.toLowerCase();
if (/android/i.test(uaName)) url = androidUrl;
else { if (/ip(hone|od)/i.test(uaName)) url = iphoneUrl;
else { if (/symbian/i.test(uaName)) url = symbianUrl;
else { if (/windows (ce|phone)/i.test(uaName)) url = windowsPhoneUrl;
else url = defaultUrl;
}
}
}
//document.writeln(uaName);
}
else { url = defaultUrl; }
window.location.href = url;
}
</script>
<style type="text/css">
<!--
.STYLE1 {
font-size: 16px;
font-weight: bold;
}
.STYLE2 {font-size: 14px}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /></head>
<body onload='checkOS();'>
<p> </p>
<p class="STYLE1">请稍后,正在检测您的设备类型。</p>
</body>
</html>