JS Judge Mobile Access page, according to mobile phone access or PC access to jump

Source: Internet
Author: User

When users visit your site, if it is PC-side access, then do not do, if it is mobile phone or tablet access, jump to their own definition of the mobile phone page, this is often used when doing webapp, the code to share to everyone, I hope to help you.

First, you have to refer to a JSUAREDIRECT.JS,JS source in the page as follows:

functionUaredirect (f) {Try{if(document.getElementById ("Bdmark")! =NULL){return}varb=false;if(Arguments[1]) {varE=window.location.host;varA=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) {varC=window.location.hash;if(!c.match ("Fromapp")) {if((Navigator.userAgent.match (/(iphone|ipod| Android|ios))) {Location.replace (f)}}}}Catch(d) {}}functionIssubdomain (c,d) { This. getdomain=function(f) {varE=f.indexof ("://");if(e>0) {varH=f.substr (E+3)}Else{varH=F}varg=/^www\./;if(G.test (h)) {H=H.SUBSTR (4)}returnh};if(C==d) {return1}Else{varC= This. GetDomain (c);varb= This. GetDomain (d);if(c==b) {return1}Else{C=c.replace (".", "\ \.");varA=NewREGEXP ("\ \") +c+ "$");if(B.match (a)) {return2}Else{return0}}};
View Code

Then call:

<script type= "Text/javascript" >uaredirect ("http://www.weixh.net/wap/", "http://www.weixh.net"); </script >

The previous parameter for the mobile phone page, the following parameters for your site's domain name, you need to pay attention to: Put the two JS to the head of the page, can not let the mobile phone users see the content of the computer page and then jump, this effect is poor.

Yi Read the net to use this, but the phone page directly with Baidu WebApp generated, the effect is not very good, we can go to see www.eadu123.com

JS Judge Mobile Access page, according to mobile phone access or PC access jump

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.