Using Baidu Siteapp uaredirect.js to judge the user access to the domain name of the auto-jump

Source: Internet
Author: User

First, embed this code in your head.

<script src= "Http://siteapp.baidu.com/static/webappservice/uaredirect.js" type= "Text/javascript" ></ Script>

<script type= "Text/javascript" >uaredirect ("http://m.caijiayou.com", "http://www.caijiayou.com"); </ Script>

The second line of the style reference this is OK. Change the domain name inside to your own.

Here we can see, this is quoted Baidu Siteapp Uaredirect.js

So you can also download the JS file to your website locally.

: Http://siteapp.baidu.com/static/webappservice/uaredirect.js

We'll format the uaredirect.js.

uaredirect.js after formatting

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
}
}
}
};

From the above JS can be seen in the different access to the judgment.

Using Baidu Siteapp uaredirect.js to judge the user access to the domain name of the auto-jump

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.