效果
把代码加入html中,打开网页会自动跳转到腾讯待办小程序。
同理修改代码也可达到跳转其它小程序的目的。
官网截图
代码
<script>
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
}
return null;
}
// 跳转至小程序
if(getUrlParam('target') === 'miniprogram' && !getUrlParam('path')) {
location.href='weixin://dl/business/?t=sllFuPPYHYb'; // 列表页
}
// 跳转至APP
if (getUrlParam('target') === 'app') {
var ua = navigator.userAgent.toLocaleLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
document.getElementById('wechat').style.display='block';
}
if (getUrlParam('type') === 'todo') {
location.href = 'todolist://list?scene=' + getUrlParam('sid');
} else {
location.href = 'todolist://';
}
}
</script>
如果本文对你有所帮助,还请关注我持续更新更多精彩内容,感谢!