通过超链接打开App应用

通过超链接打开App应用

URL schemes, 通过超链接打开App应用

var mobileAppInstall = (function () {
var ua = navigator.userAgent,
loadIframe,
win = window,
isIPad = ua.match(/iPad/i) != null,
isIphone = !isIPad && ((ua.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPod/i) != null)),
isIOS = isIPad || isIphone,
isAndroid = !isIOS && ua.match(/android/i) != null,
isMobile = isIOS || isAndroid; function getIntentIframe() {
if (!loadIframe) {
var iframe = document.createElement("iframe");
iframe.style.cssText = "display:none;width:0px;height:0px;";
document.body.appendChild(iframe);
loadIframe = iframe;
}
return loadIframe;
}
function getPlayUrl(iVideoID, sLy) {
var videoplayURL = iVideoID == "" ? "" : "http://m.video.baomihua.com/m/" + iVideoID;
videoplayURL = videoplayURL == "" ? "" : videoplayURL + (sLy == "" ? "" : "_ly=" + sLy);
return videoplayURL;
}
var appInstall = {
isChrome: ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/),
isAndroid: ua.match(/(Android);?[\s\/]+([\d.]+)?/),
isWeixin: ua.match(/MicroMessenger/i) != null,
isUC: ua.match(/UCBrowser/i) != null,
timeout: 500,
/**
* 尝试跳转appurl,如果跳转失败,进入h5url
* @param {Object} appurl 应用地址
* @param {Object} chromeurl 应用地址
* @param {Object} h5url http地址
*/
open: function (appurl, chromeurl, h5url) {
var t = Date.now();
appInstall.openApp(appurl);
setTimeout(function () {
if (Date.now() - t < appInstall.timeout * 2 + 100) {
h5url && appInstall.openH5(h5url);
}
}, appInstall.timeout) },
openApp: function (appurl) {
if (appInstall.isChrome) {
if (appInstall.isAndroid) {
win.location.href = chromeurl;
} else {
win.location.href = appurl;
}
} else {
getIntentIframe().src = appurl;
}
},
openH5: function (h5url) {
win.location.href = h5url;
},
playvideo: function (ivideoid, ichannelid, sLy) {
var videoplayURL = getPlayUrl(ivideoid, sLy);
if (sLy == "uc" || sLy == "bdqyy") {
window.location = videoplayURL;
return;
}
if (!isAndroid || appInstall.isWeixin || appInstall.isUC) {
window.location = videoplayURL;
return;
} appurl = getAndroidAppUrl(ichannelid, ivideoid, sLy);
chromeurl = getChromeIntent(ichannelid, ivideoid, sLy);
var sRedirect = getDownLoadURL(ichannelid, ivideoid, sLy);
mobileAppInstall.open(appurl, chromeurl, sRedirect);
}
} return appInstall;
function getDownLoadURL(iChannelid, iVideoid, sLy) {
var downloadUrl = "http://m.video.baomihua.com/play2/player/dlVideoApp.htm?videoid=" + iVideoid;
downloadUrl = downloadUrl + (iChannelid == "" ? "" : "&channelid=" + iChannelid);
downloadUrl = downloadUrl + (sLy == "" ? "" : "&ly=" + sLy);
return downloadUrl;
}
function getAndroidAppUrl(iChannelid, iVideoid, sLy) {
var dl = "pmhapp://video.view/play";
switch (parseInt(iChannelid)) {
case 13:
dl = "pmhapp://video.view/play";
break;
case 3:
dl = "pmhapp://video.view/play";
break;
case 55:
dl = "pmhgcw://video.view/play";
break;
default:
dl = "pmhapp://video.view/play";
break;
}
return dl + "?id=" + iVideoid + (sLy ? "&ly=" + sLy : "");
}
function getChromeIntent(iChannelid, iVideoid, iLy) {
// 根据自己的产品修改吧
var dl = "intent://video.view/play?id=" + iVideoid + (iLy ? "&ly=" + iLy : "") + "#Intent;scheme=pmhapp;package=com.com.baomihuawang.androidclient;end";
switch (parseInt(iChannelid)) {
case 13:
dl = "intent://video.view/play?id=" + iVideoid + (iLy ? "&ly=" + iLy : "") + "#Intent;scheme=pmhapp;package=com.com.baomihuawang.androidclient;end";
break;
case 3:
dl = "intent://video.view/play?id=" + iVideoid + (iLy ? "&ly=" + iLy : "") + "#Intent;scheme=pmhapp;package=com.com.baomihuawang.androidclient;end";
break;
case 55:
dl = "intent://video.view/play?id=" + iVideoid + (iLy ? "&ly=" + iLy : "") + "#Intent;scheme=pmhgcw;package=com.com.baomihuawang.androidclient;end";
break;
default:
dl = "intent://video.view/play?id=" + iVideoid + (iLy ? "&ly=" + iLy : "") + "#Intent;scheme=pmhapp;package=com.com.baomihuawang.androidclient;end";
}
return dl;
}
})();
<a class="link" href="javascript:mobileAppInstall.playvideo(35846544,8,'');"></a>
05-11 15:23