Inside the WeChat applet, open the H5 through the web-view to jump to the applet page (judging whether the H5 is opened inside the WeChat applet or externally)

	goWeapp() {
				var ua = navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == "micromessenger") {
					// ios的ua中无miniProgram,但都有MicroMessenger(表示是微信浏览器)
					wx.miniProgram.getEnv((res) => {
						if (res.miniprogram) {
							console.log('在小程序里')
							wx.miniProgram.navigateTo({
								url: `/packageA/pages/acPreviewMS/index?StoreId=${this.PromotionInfo.StoreId}&acId=${this.PromotionInfo.ActivityId}&AcType=${this.activityDetail.AcType}`,
								success(res) {
								    console.log(res) // 输出:{ errMsg: "navigateTo:ok" }
								  },
								  fail(res) {
								    console.log(res) // 输出:{ errMsg: "navigateTo:fail" }
								  }
							})

						} else {
							console.log('不在小程序里');
							this.goActiveDetail();
						}
					})
				} else {
					console.log('不在微信里')
					this.goActiveDetail();

				}



			},
goActiveDetail() {
				var that = this;
				// 先判断是不是pc端打开的h5 如果是pc端提醒用手机打开页面
				if (window.navigator.userAgent.indexOf("Windows") != -1) {
					window.alert("请使用手机打开!")
				} else {
					// 调取接口获取URL Scheme
					let params =
	`StoreId=${that.PromotionInfo.StoreId}&acId=${that.PromotionInfo.ActivityId}&AcType=${that.activityDetail.AcType}`
					console.log(params)
					$.post('/api/wx/GenerateScheme', {
							Path: "packageA/pages/acPreviewMS/index", //打开的小程序页面路径
							Query: params,
							// env_version: "trial" //  正式版为"release",体验版为"trial",开发版为"develop"
						})
						.then(res => {
							let UrlScheme = res.Data
							setTimeout(() => {
								window.open(UrlScheme);
							}, 200)
						})

				}
			},

web-view | WeChat open document 
WeChat external jump applet page For details, please refer to my previous article h5 jump WeChat applet (applicable to both internal browsers and external browsers of WeChat) CSDN blog

Guess you like

Origin blog.csdn.net/qq_46376192/article/details/131250695