Determine whether the page is opened on the pc side or on the mobile side

In project development, it will be encountered that opening pages in different devices are different, such as:

I open a website in mobile phone and open a website in pc, the page is different

The specific implementation is as follows

/ / Determine the terminal that opens the website
var ua = window.navigator.userAgent.toLocaleLowerCase()
var reg =/iphone|android|symbianos|windows\sphone/g

if (reg .test(ua )) {
    window.location.href = 'The address opened by the mobile terminal'
}else{
      window.location.href = 'The address opened on the pc side'
}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324908357&siteId=291194637