怎么判断h5网页是在浏览器中打开,还是在app中打开的
![哈哈6](https://img-cdn-tc.dcloud.net.cn/account/identicon/d5c6e410478aaab7533b73b6b868ab96.png)
- 发布:2023-07-26 11:15
- 更新:2023-07-26 13:23
- 阅读:1420
![DCloud_App_Array](http://img-cdn-tc.dcloud.net.cn/uploads/avatar/000/00/00/46_avatar_mid.jpg?v=0)
User Agent中有Html5Plus、uni-app表示是在uni-app打包的App中:
https://uniapp.dcloud.net.cn/tutorial/app-useragent.html#%E9%BB%98%E8%AE%A4user-agent
![人生不设限](https://img-cdn-tc.dcloud.net.cn/account/identicon/adfdfb73b4fc6fb7e4e5797c6b8423f6.png)
如果是通过web-view加载的h5页面,最简单的就是在onLoad的时候判断window.plus是否存在,存在就是uniapp不存在就是其他环境
-
-
-
哈哈6 (作者)
回复 人生不设限: function plusReady(){
if(window.plus) {
document.write('2222');
}
document.write('3333');
}
function brower() {
if(window.plus){
plusReady();
}else{
document.addEventListener('plusready',plusReady,false);
}
return '111';
}
document.write(brower());
我是这样写的但是根本就不会打印出222,333
2023-07-26 12:09
-
哈哈6 (作者)
我打印出ua但是并没有看到uniapp相关标志啊,看上图
2023-07-26 11:36