一个项目是app+微信公众号h5页面,总会遇到一些在app中可以使用但普通h5页面用不了的api,
比如“扫一扫”
对浏览器的UserAgent进行正则匹配,不含有微信独有标识的则为其他浏览器:
var useragent = navigator.userAgent.toLowerCase();
if (useragent.indexOf(‘micromessenger’) === -1) {
// micromessenger微信独有标识 这个关键
// 停止代码继续执行,并弹出提示框
return alert(‘请在微信客户端访问本页面’);
}
uniapp:
设置url只能在微信中打开,其他页面给提醒,适用微信公众号等H5页面

相关文章:

  • 2021-12-04
  • 2021-11-25
  • 2021-11-23
  • 2021-12-24
  • 2022-01-22
  • 2022-12-23
  • 2021-05-19
  • 2021-11-18
猜你喜欢
  • 2021-11-29
  • 2021-12-06
  • 2021-11-25
  • 2022-12-23
  • 2021-05-12
  • 2021-12-20
相关资源
相似解决方案