Baidu Judge Mobile terminal and automatically jump Uaredirect.js code and use examples

Source: Internet
Author: User

Baidu Siteapp under the product of a jump, use is very convenient. You can use this JS to jump to the mobile version, you can also jump to any location you want to jump.

The JS code 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)/i)) {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)        }        returnh}; if(c = =d) {return1    } Else{var c= This. GetDomain (c); var b= This. GetDomain (d); if(c = =b) {return1        } Else{C= C.replace (".", "\ \.")); var a=NewREGEXP ("\ \" + C + "$")); if(B.match (a)) {return2            } Else {                return0            }        }    }};

How to use:

Save the above code for Uaredirect.js, the reference to this JS file is best placed under the title of the site, do not put in the last or other parts, this is because it will load uaredirect.js after the jump, This will be done quickly , if you first load other JS or CSS, will load them before jumping, so that the jump speed will be very slow. loading, just a piece of code will be OK .

Reference code:

<script src= "Your JS storage directory/uaredirect.js" type= "Text/javascript" ></script><script type= "Text/javascript ">uaredirect (" http://m.haishiit.com "," http://www.haishiit.com ");</script>

Description:http://m.haishiit.com is a mobile version of the website, http://www.haishiit.com is a computer version of the website.

Baidu Judge Mobile terminal and automatically jump Uaredirect.js code and use examples

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.