下面是测试网页的内容:
<html>
<head><script type="text/javascript">
//判断手机上是否安装了app,如果安装直接打开,如果没安装,跳转到下载页面
function openApp(url) {
var timeout, t = 1000, hasApp = true;
var openScript = setTimeout(function () {
if (!hasApp) {
var durl = "http:www.baidu.com";
window.location.href=durl;
}
document.body.removeChild(ifr);
}, 2000)
var t1 = Date.now();
var ifr = document.createElement("iframe");
ifr.setAttribute('src', url);
ifr.setAttribute('style', 'display:none');
document.body.appendChild(ifr);
timeout = setTimeout(function () {
var t2 = Date.now();
if (!t1 || t2 - t1 < t + 100) {
hasApp = false;
}
}, t);
}
</script>
</head>
<body >
<input type="hidden" id="downloadUrl" name="downloadUrl" value="http:www.baidu.com"/>
<div>
<a href="javascript:void(0);" οnclick='openApp("zdykapphaoyuntao://");' >Client</a>
</div>
<br/>
</body>
</html>
客户端以android举例:需要在AndroidManifest.xml文件启动activity下面加入 <data android:scheme="zdykapphaoyuntao" />
这样配置好后就在可以启动的activity里面拿到各种需要的数据:如下
Intent intent = getIntent();
Uri data = intent.getData();
if (null != data) {
String host = data.getHost();
String path = data.getPath();
String query = data.getQuery();
if (host.equals("productdetail")) {// 商品详情
intent = new Intent(ActWelcomeNow.this, ActGoodsDetail.class);
intent.putExtra(Contant.NAME, query);
ActWelcomeNow.this.startActivity(intent);
ActWelcomeNow.this.finish();
} else if (host.equals("shopindex")) {// 店铺首页
intent = new Intent(ActWelcomeNow.this, ActShopIndex.class);
intent.putExtra(Contant.NAME, query);
ActWelcomeNow.this.startActivity(intent);
ActWelcomeNow.this.finish();
}
最后
以上就是幸福路灯最近收集整理的关于网页判断判断是否安装APP并启动,没有安装就跳转到下载页面的全部内容,更多相关网页判断判断是否安装APP并启动内容请搜索靠谱客的其他文章。
发表评论 取消回复