<!-- <nav-bar title="{{titleName}}"></nav-bar> -->
<web-view src="{{urlString}}"></web-view>
// assemblyPage/pages/thirdWebView/thirdWebView.js
Page({
/**
* 页面的初始数据
*/
data: {
urlString:'',
titleName:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let that = this;
const eventChannel = that.getOpenerEventChannel()
eventChannel.on('getData', function (data) {
console.log(data, '7777');
// that.data.detail = data;
that.setData({
// urlString: data.webUrl,
urlString:'http://10.2.0.99:5500/demo.html',
titleName:data.webName
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
<html>
<head>
<title>打开小程序</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<script>
function ruleEnvFunction () {
let type = 0;
let ua = navigator.userAgent.toLowerCase();
alert(ua)
if (ua.match(/MicroMessenger/i) == "micromessenger") {
//ios的ua中无miniProgram,但都有MicroMessenger(表示是微信浏览器)
wx.miniProgram.getEnv((res) => {
if (res.miniprogram) {
alert("在小程序里");
type = 1;
// if (goUrl) {
// navigateTo 打开新页面 保留当前页面
// redirectTo 打开新页面 关闭当前页面
// switchTab 跳转到tabBar页面(底部切换页)
// wx.miniProgram.navigateTo({ url: '/functionPage/pages/zhuanShuGuWen/zhuanShuGuWen' })
// }
} else {
type = 2;
alert("不在小程序里");
}
})
} else {
type = 3;
alert('不在微信里');
}
return type;
}
function openPageBtn (url, type) {
// type 1 tabBar页面 2非tabBar页面
let env = ruleEnvFunction()
if (env == 1) {
// navigateTo 打开新页面 保留当前页面
// redirectTo 打开新页面 关闭当前页面
// switchTab 跳转到tabBar页面(底部切换页)
// wx.miniProgram.navigateTo({ url: '/functionPage/pages/zhuanShuGuWen/zhuanShuGuWen' })
// wx.miniProgram.redirectTo({ url: '/functionPage/pages/zhuanShuGuWen/zhuanShuGuWen' })
wx.miniProgram.switchTab({ url: '/pages/home/home' })
} else {
alert('请在微信打开小程序')
}
}
</script>
</head>
<body>
<button onclick="openPageBtn()">点击跳转</button>
</body>
</html>