最新方法:
h5和app之间的跳转
微信开放标签
1.跳转APP:wx-open-launch-app
官方文档:
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html#22
<div class="goods_xf" id="goods_xf">
<wx-open-launch-app
id="launch-btn"
appid="wxfcc4c272c838f53d"
extinfo=""
>
<template>
<style></style>
<div>打开app</div>
</template>
</wx-open-launch-app>
</div>
2.跳转小程序:wx-open-launch-weapp
官方文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html#21
h5跳转小程序
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
wx.miniProgram.navigateTo({ url: '/packageActivity/redPacket/open' })
以下为旧的方法:
1.浏览器跳转app
<div id="openApp"></div>
<script type="text/javascript">
document.getElementById('openApp').onclick = function(e) {
//ios
if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
var browser = navigator.userAgent.toLowerCase();
if(browser.match(/micromessenger/i)) {
//微信内置浏览器
window.location.href ="PigTrading://"; ios跳转app协议
window.setTimeout(function() {
window.location.href = "https://itunes.apple.com/cn/app/zhu-yi-tong/id904595949?l=en&mt=8";
}, 1000)
return
} else {
window.location.href ="PigTrading://"; // ios跳转app协议
window.setTimeout(function() {
window.location.href = "https://itunes.apple.com/cn/app/zhu-yi-tong/id904595949?l=en&mt=8";
}, 2000)
return
}
}
if(navigator.userAgent.match(/android/i)) {
//Android
window.location.href = "zyt://zhuetong/wzydetail?aid=$aid";//android跳转协议
window.setTimeout(function() {
window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.lty.zhuyitong"
}, 2000)
return
}
};
</script>
2.微信端浏览器跳转app
使用微信开放标签
官方文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html
<wx-open-launch-app
id="launch-btn"
appid="app的id"
extinfo="传值给app (如果要调到指定页面可用)"
>
<div></div>
<template>
<style>.btn { padding: 12px }</style>
<button class="btn">App内查看</button>
</template>
</wx-open-launch-app>
<a href="https://www.zhue.cn/shop-sdlc.html" target="_blank">https://www.zhue.cn/shop-sdlc.html</a>
<script>
url=location.href;
$.ajax({
type : "post",
url : "获取信息的地址",
data : {posturl:url},
success : function(data){
console.log(data)
var data = eval("0,("+data+")");
wx.config({
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
debug: false,
signature: data.signature,
jsApiList: [
"onMenuShareTimeline"
],
openTagList: ['wx-open-launch-app'] // 可选,需要使用的开放标签列表,例如['wx-open-launch-app']
});
}
});
var btn = document.getElementById('launch-btn');
btn.addEventListener('launch', function (e) {
alert('success');
});
btn.addEventListener('error', function (e) {
// "launch:fail" 调用失败,或安卓上该应用未安装,或iOS上用户在弹窗上点击确认但该应用未安装
// "launch:fail_check fail" 校验App跳转权限失败,请确认是否正确绑定AppID
alert('fail111', e.detail);
});
btn.setAttribute('extinfo', `"${url}"}`)
</script>