[removed] How to detect if the user is using UC Browser/Mini?

后端 未结 3 1967
时光说笑
时光说笑 2020-12-06 13:49

I am creating a website that is not rendered properly in UC Browser/Mini. I am planning to override the style using javascript. Thanks in advance.

3条回答
  •  没有蜡笔的小新
    2020-12-06 14:08

    Use the navigator.userAgent to see if either Opera Mini or UC Browser is being used.

    The following example is how to detect if UCBrowser is being used

    if (navigator.userAgent.indexOf(' UCBrowser/') >= 0) {
       //  do stuff here
    }
    

    The navigator.userAgent will return a list of stuff in string. Like the example above, navigation.userAgent will return a string of stuff where "UCBrowser" is included as the javascript is used in UC Browser. So the snippet above therefore indexes for such line and determine the condition should the indexed line be found in the userAgent output.

    I am not sure whether this will work since I have trouble trying to test my local files on Opera Mini, but based on my research, the below code may work.

    if (navigator.userAgent.indexOf('Opera Mini') >= 0) {
       //  do stuff here
    }
    

提交回复
热议问题