手机网页唤起uniapp

1、uniapp打包指定scheme,如图

 2、手机浏览器换起app代码scheme://,window.location.href = 'aaa://',aaa为上图填写的UrlSchemes

常见的应用UrlScheme如下:

微信URL scheme:weixin://

支付宝URL scheme:alipayqr://

抖音URL scheme:snssdk1128://

快手URL scheme::kwai://work//

如何获取应用UrlScheme?

反编译apk文件,获取AndroidManifest.xml中的scheme,执行命令java -jar apktool.jar d apkfile dir

由于此jar无法上传,需要可以私信

最终附上微信扫一扫,使用浏览器下载或换起app的代码

<!DOCTYPE html>
<head>
	<meta charset="UTF-8">
	<title>xx系统</title>
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
	<meta content="yes" name="apple-mobile-web-app-capable" />
	<meta content="black" name="apple-mobile-web-app-status-bar-style" />
	<meta name="format-detection" content="telephone=no" />
	<meta content="false" name="twcClient" id="twcClient" />
	<link rel="stylesheet" type="text/css" href=".css/style.css" />
	<script type="text/javascript" src="js/open.js"></script>
</head>
<style type="text/css">
	.outer7 {
		height: 100%;
		background: url(img/bg.png);
		100% no-repeat;
		width: 100%;
		background-size: 100% 100%;
		position: absolute;
	}

	.outer8 {
		width: 100%;
		position: absolute;
		bottom: 25%;
	}

	.Button {
		background-color: #3963ea;
		border-radius: 54px;
		height: 44px;
		width: 69.33333%;
		line-height: 44px;
		color: #fff;
		font-size: 16px;
		margin: auto;
		cursor: pointer;
	}

	.Button3 img {
		width: 19px;
		height: 22px;
		display: block;
		float: left;
		margin-top: 11px;
		margin-right: 9px;
	}

	.Button1 {
		margin-bottom: 10px;
		display: flex;
		justify-content: center;
	}

	.Button2 {
		text-align: center;
	}

	.desc {
		margin: auto;
		text-align: center;
		margin: 16px;
		color: #909090;
		font-size: 12px;
	}

	.wxtip {
		background: rgba(0, 0, 0, 0.8);
		text-align: center;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 9999999998;
		display: none;
	}

	.wxtip-icon {
		width: 52px;
		height: 67px;
		background: url(images/weixin-tip.png) no-repeat;
		display: block;
		position: absolute;
		right: 20px;
		top: 20px;
	}

	.wxtip-txt {
		margin-top: 107px;
		color: #fff;
		font-size: 16px;
		line-height: 1.5;
	}
</style>
<body style="height: 100%;width: 100%;margin: 0px;">
	<div class="outer7">
		<div class="outer8">
			<!-- <div class="desc">
				目前仅支持Android版本
			</div> -->
			<div class="Button Button1" id="downloadApp" onclick="toDownload()">
				<div class="Button3">
					<img src="img/icon_3.png" />
					Android版本下载
				</div>
			</div>
			<div class="Button Button1" id="downloadIosApp" onclick="toIosDownload()">
				<div class="Button3">
					<img src="img/ios.png" />
					IOS版本下载
				</div>
			</div>
			<div class=" Button Button2 " id="openApp" onclick="evokeByIFrame()">
				打开xx系统APP
			</div>
		</div>
	</div>
	<div class="wxtip" id="JweixinTip">
		<span class="wxtip-icon"></span>
		<p class="wxtip-txt">点击右上角<br />选择在浏览器中打开</p>
	</div>
	<script>
		var url = "http://xx.apk"; //安装包的地址
		window.mobileUtil = (function(win, doc) {
			var UA = navigator.userAgent,
				isAndroid = /android|adr/gi.test(UA),
				isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid,
				isBlackBerry = /BlackBerry/i.test(UA),
				isWindowPhone = /IEMobile/i.test(UA),
				isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone;
			return {
				isAndroid: isAndroid,
				isIOS: isIOS,
				isMobile: isMobile,
				isWeixin: /MicroMessenger/gi.test(UA),
				isQQ: /QQ/gi.test(UA)
			};
		})(window, document);

		function toDownload() {
			if (mobileUtil.isWeixin) {
				if (mobileUtil.isIOS) {
					window.location.href = url;
				} else if (mobileUtil.isAndroid) {
					document.getElementById('JweixinTip').style.display = 'block';
					document.getElementById('JweixinTip').onclick = function() {
						document.getElementById('JweixinTip').style.display = 'none';
					};
				}
			} else {
				window.location.replace(url);
			}
		};

		function getParam(key) {
			let that = this;
			// window.location.href 获取地址
			let url = window.location.href;
			let p = url.split('?')[1]
			let params = new URLSearchParams(p);
			return params.get(key);
		}
		var carId = getParam('carId');
		// if (type == 'report') {
		function evokeByIFrame() {
			window.location.href = 'xx://'
			if (mobileUtil.isWeixin) {
				toDownload();
				return;
			}
		}
		
		function toIosDownload(){
			window.location.href = 'itms-apps://itunes.apple.com/cn/app/idxx'
		}
		
		if (mobileUtil.isIOS) {
			toIosDownload()
		} else {
			if (!mobileUtil.isWeixin && mobileUtil.isMobile) {
				evokeByIFrame();
			}
		}
		// } else {
		// 	if (!mobileUtil.isWeixin && mobileUtil.isMobile) {
		// 		window.location.replace(url);
		// 	}
		// }
	</script>
</body>
</html>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值