Baidu Judge handset terminal and automatically jump JS code and use instance _javascript skill

Source: Internet
Author: User

Baidu currently provides the webmaster to judge the type of mobile phone terminal and automatically jump to the JS script, greatly facilitated the vast number of webmaster and web developers. The use of its JS script is extremely simple.

Copy Code code as follows:

<script src= "Http://siteapp.baidu.com/static/webappservice/uaredirect.js" type= "Text/javascript" ></ Script>
<script Type=text/javascript>uaredirect ("mobile phone Station", "Web Station");</script>

One of the most central JS script format code is as follows:
Copy Code code 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)
}
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
}
}
}
};

Webmaster and web Developers are advised to use the following compressed JS script
Copy Code code 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 (h)) {G.test (4) h=h.substr 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}}}};

PS: In this small series for everyone to recommend a few JavaScript format landscaping and compression tools, similar to the above Baidu jump code compression and formatting can be used to implement the following tools:

C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json

Online JavaScript code Landscaping, formatting tools:
Http://tools.jb51.net/code/js

JavaScript code Landscaping/compression/formatting/encryption Tools:
http://tools.jb51.net/code/jscompress

JavaScript Online compression Tool:
Http://tools.jb51.net/code/js_yasuo

JavaScript Online formatting tool (based on Beautify.js plugin):
Http://tools.jb51.net/code/js_beautify

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.