Vue determines whether it is an Android ios WeChat browser environment!

Recent company development projects require embedded H5 interfaces for ios and Android, WeChat browsers, and small programs to make judgments on different environments and then do different things. Here is a simple add-to-cart and jump-to-details page function. Not much to say. Say share my code below!

First, it is judged to be a small program environment!

if(window.__wxjs_environment == 'miniprogram'){
    
    }
 if (window.__wxjs_environment == 'miniprogram') {
    
    
    wx.miniProgram.navigateTo({
    
    url: '/pages/components/share/details/details?id='+id })
	return;
  }

Second, it is judged to be the WeChat browser environment!

if (/(MicroMessenger)/i.test(navigator.userAgent)) {
    
    }
 if (/(MicroMessenger)/i.test(navigator.userAgent)) {
    
    
    window.location.href = 'https://h5.fcdsx.com/#/shopdetail?recommendid=' + id
   }

Third, it is judged to be an ios iPad environment!

if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
    
    }
 if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
    
    
   var url="product:"+id;
   document.location = url;
  } 

Fourth, it is judged to be an Android environment!

if (/(Android)/i.test(navigator.userAgent)) {
    
    }
if (/(Android)/i.test(navigator.userAgent)) {
    
    
     window.productweb.goProduct(id);
   }

Guess you like

Origin blog.csdn.net/weixin_46533797/article/details/108070971