Achieve mobile phone access, automatic jump website mobile version

Source: Internet
Author: User

Baidu site app Uaredirect.js realize mobile phone access, automatic jump website mobile version

The following code, can be placed in the site foot the bottom of the file, or haead the top file, it is recommended to put the code at the top of the site, so that you can achieve mobile Access immediately jump!

<script src= "Http://siteapp.baidu.com/static/webappservice/uaredirect.js" type= "Text/javascript" ></ Script><script type= "Text/javascript" >uaredirect ("http://m.jiuquan.cc");</script>

Change the Code URL section to your website's mobile URL is ok, of course, can be any URL!

This should be the legendary WAP auto Jump!

Transfer from: Link

JS Judge user access terminal type (uaredirect.js)

Don't use the big string of judgments on the Internet before using it.

Before the use of emlog when someone used this method, now found that Baidu Siteapp also provide this method

<script src= "http://siteapp.baidu.com/static/webappservice/uaredirect.js" type= "Text/javascript" > </script><script type= "Text/javascript" >uaredirect ("http://m.baidu.com");</script>

Use useragent to judge (iphone|ipod| Android|ios|ipad)

function Uaredirect (murl) {    try {        if (document.getElementById ("bdmark") = null) {            return;        }        var urlhash = Window.location.hash;        if (!urlhash.match ("Fromapp")) {            if (Navigator.userAgent.match (/(iphone|ipod| Android|ios|ipad)) {                location.replace (Murl)}}}    catch (Err) {}}

Uaredirect.js

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 = wi            Ndow.location.hash; if (!c.match ("Fromapp")) {if (Navigator.userAgent.match (/(iphone|ipod| Android|ios)/i)) {Location.replace (f)}}}} catch (d) {}}functio n Issubdomain (c, d) {this.getdomain = function (f) {varE = F.indexof ("://");        if (E > 0) {var h = f.substr (E + 3)} else {var h = f} var g =/^www./;    if (G.test (h)) {h = h.substr (4)} return H};        if (c = = d) {return 1} else {var c = This.getdomain (c);        var B = This.getdomain (d);            if (c = = b) {return 1} else {c = C.replace (".", "\.");            var a = new RegExp ("\." + C + "$"); if (B.match (a)) {return 2} else {return 0}}};

Compress code

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)) {location.replace (f)}}}}catch (d) {}}function Issubdomain (c,d) {this.getdomain=function (f) {var e= F.indexof ("://"), if (e>0) {var h=f.substr (e+3)}else{var H=f}var g=/^www./;if (g.test (h)) {H=h.substr (4)}return H}; if (C==d) {return 1}else{var c=this.getdomain (c); var b=this.getdomain (d); if (c==b) {return 1}else{c=c.replace (".", "\."); var a=new RegExp ("\.") +c+ "$"); if (B.match (a)) {return 2}else{return 0}}};
Transfer from: Link

Through the JS file to achieve access to the site automatically jump to the mobile station

Baidu site app through the site, you can add JS judgment in the head section of the website, if it is mobile Access automatically jump to the phone address:

<script src= "Http://siteapp.baidu.com/static/webappservice/uaredirect.js" type= "Text/javascript" ></ Script><script type= "Text/javascript" >uaredirect ("http://m.429006.com");</script>

Take a closer look at this JS file: uaredirect.js

function Uaredirect (murl) {
try {
if (Document.getelEmentbyid ("bdmark") = null) {
Return
}
var urlhash = Window.location.hash;
if (!urlhash.match ("Fromapp")) {
if (Navigator.userAgent.match (/(iphone|ipod| Android|ios|ipad))) {
Location.replace (Murl);
}
}
} catch (Err) {}
}

This is a mobile device judge, using useragent to judge, iphone|ipod| Android|ios|ipad, elder brother, you are not these systems or equipment on the pull over ...

Here to give us an inspiration, you can use this JS to make a judgment device, and then do something you want to do.

Transfer from: Link

Here is the Chinese good buy hand automatically jump in the PC-side project start page, detected from the mobile phone to access, automatically jump to the WAP service

Achieve mobile phone access, automatic jump website mobile version

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.