Get the App
SLTechnology News&Howtos  ›  Servers  › 

About judging whether web is accessed by mobile phone or computer, and the implementation of copy and delete button

Shulou Source: shulou.com Published: 2022-06-02 07:02:33 10月04日 Update

As smartphones become more and more popular, more computer applications will launch mobile phone versions, such as websites. As computers and mobile phones visit the page when the js,css will be different, so you need to determine whether the phone or computer login, to display different pages to achieve a better user experience!

One: the method to determine whether the mobile end or the computer side accesses WEB.

1.js judgment

Var useragent=window.navigator.userAgent

Alert (useragent)

Useragent is some information of the browser, for example, when I access it with a computer browser, it will pop up (using an IE10,chrome,safari,firfox browser to do an experiment)

When the mobile browser is accessed, it pops up (the phone uses an opera analog browser)

In this way, you can use functions such as indesof,contains to judge and jump to different pages.'

2.java

In fact, in java code, it is very similar to js judgment, my method is:

If (userAgents.indexOf ("Windows")! =-1) {

Return new DefaultHttpHeaders ("computer side Jump Page jsp name"). DisableCaching ()

}

Else {

Return new DefaultHttpHeaders ("Mobile Jump Page jsp name"). DisableCaching ()

}

I operate in this way, there must be other ways, please leave a message to tell me, little brother very much thank you first!

Tags: Mobile phone computer browser page browsing method or different name time code information function big god little brother that is difference intelligence more version Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB Docker Xiaomi macOS