Recently, we have been busy with our team's project "Wings of Coffee", in which we provide an excellent experience for the mobile platform. With the prosperity of the Android platform. Not only has it driven the domestic smartphone industry, but many domestic developers have also begun to devote themselves to the big wave of Android mobile terminals. If you missed a lot of Internet waves. Then you must not miss this Android wave. At present, we have developed mobile terminals and Android clients for "Coffee Wings". Everyone uses Android or IOS operating system mobile phones and directly access the domain name www.sygxy.cn to watch the mobile terminal effects. At the same time, Android clients have been launched in Tencent’s “Application Treasure” and “Baidu Mobile Assistant” application stores. You can search for "Wings of Coffee" directly to download. Without any promotion, it has only been released for one week and has more than 100 downloads.
If you need to optimize the mobile terminal, what you must do is to determine what the client's access device is. Through the judgment result, return the domain name address that cannot be used, and then load different CSS files.
The judgment method we use is to make judgments through the user-agent value. Use the userAgent property of the Navigator object in the javascript framework. There is no public standard for navigator objects, but this object is now supported by all browsers on the market. Use the userAgent attribute to return the value of the user-agent header of the server sent by the client. There is a User-Agent in the header information, which is used to tell the server, what browser the user client is, and the operating system information. Use regular expressions to obtain user-agent values. Determine with the local value. This matching value can be a mobile operating system such as Android or iOS, or it can be the name of the browser. If there is a match, it will jump, otherwise it will not jump and go directly to the homepage of the PC side.
For specific code implementation, we use the JavaScript script language to improve the portability of the website. There are two advantages of using this technology in my opinion.
1: It can improve the portability of the website. If our team needs to add the effect of the mobile terminal again in the subsequent web project, it can easily introduce this part of the JS code to make judgments. Improve future work efficiency.
2: The second point is to facilitate the web program to load in an unused interface, and whether to introduce this part of the mobile terminal's judgment code.
Specific implementation:
We extract the scripts to judge the access. If a page needs to be judged by the client terminal, we will directly use <script></script> to introduce the script program on the page. The specific judgment code is as follows:
The code copy is as follows:
function uaredirect(f){
try{if(
document.getElementById("bdmark")!=null){
Return
}
var b=false;
if(arguments[1]){
var e=window.location.host;var a=window.location.href;
if(isSubdomain(arguments[1],e)==1){
f=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){f=f+"/#m/"+a;b=true}
else{f=a;b=false}}}
else{b=true}if(b){var c=window.location.hash;
if(!c.match("fromapp")){
if((navigator.userAgent.match(/(iPhone|iPod|Android|ios|Windows Phone)/i))){location.replace(f)}}}}}catch(d)<br> {<br> }<br>}