js判斷請求是android還是ios,並判斷手機是否存在一個特定的程式,如果存在就開啟,不存在就下載
window.userAgentPlatform = 'PC';
window.referSite = '';
window.appProtocolLink = "";
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null)
return unescape(r[2]);
return "";
}
/**��ȡurl�ö��ַ����ַ�**/
function GetParam(paramName) {
paramValue = "";
isFound = false;
if (this.location.search.indexOf("?") == 0
&& this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1,
this.location.search.length).split("&");
i = 0;
while (i < arrSource.length && !isFound) {
if (arrSource[i].indexOf("=") > 0) {
if (arrSource[i].split("=")[0].toLowerCase() == paramName
.toLowerCase()) {
paramValue = arrSource[i].split("=")[1];
isFound = true;
}
}
i++;
}
}
return paramValue;
}
// ���referSite�ж���Դ�������ţ�
// ���isappinstalled��ֵ�ж���ת�����ҳ��
function initFunc() {
var divc = document.getElementById('guide');
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
divc.setAttribute("class", "sinaweiboiPhone");
userAgentPlatform = 'iPhone';
} else {
divc.setAttribute("class", "sinaweiboAndroid");
userAgentPlatform = 'Android';
}
var thisURL = document.URL;
var id = GetParam("id");
var isappinstalled = getQueryString("isappinstall");
if (isappinstalled == '1') {
if (userAgentPlatform == "iPhone") {
setTimeout(function() {
window.location = "=" + id;
}, 2000);
} else if (userAgentPlatform == "Android") {
setTimeout(function() {
window.location = "?id="+id;
}, 200);
}
}/*else if(isappinstalled == '0'){
} */else {
if(!navigator.userAgent.match(/(MicroMessenger);?/i))
{
if (userAgentPlatform == "iPhone")
{
document.location.href = "plist地址";
}
else if (userAgentPlatform == "Android")
{
document.location.href = "軟體地址";
}
}
}
}
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", initFunc, false);
} else {
window.onload = initFunc;
}