最近写了一H5 网页 要嵌入到安卓和ios 中,首先我们要判断用户是苹果手机 还是安卓手机 ,如果是苹果手机要传递什么参数 ,如果是安卓要传递什么参数
<script>
export default {
data() {
return {
orderNo: "",
isAppleDevice: false,
};
},
mounted() {
this.orderNo = this.$route.query.orderNo; //原生象我们传递 我们可以这样写
this.checkDevice();
},
methods: {
// 判断是否在苹果手机 还是安卓
checkDevice() {
const ua = navigator.userAgent;
if (/iPad|iPhone|iPod/.test(ua) && !window.MSStream) {
this.isAppleDevice = true;
} else if (/Android/.test(ua)) {
console.log("你在使用安卓手机");
} else {
console.log("你在使用其他手机");
}
},
orderStatus() {
if (this.isAppleDevice) {
window.webkit.messageHandlers.goHome.postMessage("畅享流量"); //象ios传递
} else {
window.handleMessage.toast("畅享流量"); //象安卓
}
},
},
};
</script>