Baidu actualmente proporciona a Webmasters con scripts JS para juzgar el tipo de terminal móvil y saltar automáticamente, lo que facilita enormemente la mayoría de los webmasters y desarrolladores web. El uso de su script JS es extremadamente simple.
La copia del código es la siguiente:
<script src = "http://siteapp.baidu.com/static/webappservice/Uaredirect.js" type = "text/javascript"> </script>
<Script type = text/javaScript> uarDirect ("sitio móvil", "sitio web"); </script>
El código de formato de script JS más central es el siguiente:
La copia del código es la siguiente:
función uaredirect (f) {
intentar {
if (document.getElementById ("bdmark")! = null) {
Devolver
}
var b = falso;
if (argumentos [1]) {
var e = window.location.host;
var a = window.location.href;
if (isSubdomain (argumentos [1], e) == 1) {
F = F + "/#m/" + A;
b = verdadero
} demás {
if (isSubdomain (argumentos [1], e) == 2) {
F = F + "/#m/" + A;
b = verdadero
} demás {
f = a;
b = falso
}
}
} demás {
b = verdadero
}
if (b) {
var c = window.location.hash;
if (! C.match ("fromapp")) {
if ((navigator.useragent.match (/(iPhone | iPod | android | iOS)/i)) {
Ubicación. Replaca (f)
}
}
}
} catch (d) {}
}
función isSubdomain (c, d) {
this.getDomain = function (f) {
var e = f.Indexof (": //");
if (e> 0) {
var h = f.substr (e + 3)
} demás {
var h = f
}
var g = /^www/./;
if (g.test (h)) {
H = H.Substr (4)
}
Regresar h
};
if (c == d) {
Devolver 1
} demás {
var c = this.getDomain (c);
var b = this.getDomain (d);
if (c == b) {
Devolver 1
} demás {
c = c.replace (".", "//.");
var a = new Regexp ("//." + C + "$");
if (b.match (a)) {
Devolver 2
} demás {
regresar 0
}
}
}
};
Se recomienda que los webmasters y los desarrolladores web usen los scripts JS comprimidos de la siguiente manera
La copia del código es la siguiente:
función uaredirect (f) {try {if (document.getElementById ("bdmark")! = null) {return} var b = false; if (argumentos [1]) {var e = window.location.host; var; var; var; a = window.location.href; if (issubdomain (argumentos [1], e) == 1) {f = f+"/#m/"+a; b = true} else {if (iss ubdomain (argumentos [1], e) == 2) {f = f+"/#m/"+a; b = true} else {f = a; b = falso}}} else {b = true} if (b) {var) c = window.location.hash; if (! C.match ("fromapp")) {if ((navigator.useragent.match (/(iPhone | iPod | android | ios)/i))) {ubicación.replace (f)}}}}}} catch (d)}} function isSubdomain (c, d) {this.get domain (f) 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} más {var c = c); 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}}}};
PD: Aquí, el editor recomienda varias herramientas de formato, embellecimiento y compresión de JavaScript. Similar a la compresión y el formato del código de salto de Baidu anterior, puede usar las siguientes herramientas para implementarlo:
C estilo de lenguaje/HTML/CSS/JSON Código de formato y herramientas de embellecimiento:
http://tools.vevb.com/code/ccode_html_css_json
Terrenos de embellecimiento y formato de código de JavaScript en línea:
http://tools.vevb.com/code/js
BATILización del código JavaScript/compresión/formato/herramientas de cifrado:
http://tools.vevb.com/code/jscompress
Herramienta de compresión en línea de JavaScript:
http://tools.vevb.com/code/js_yasuo
Herramienta de formato en línea de JavaScript (basada en el complemento Beautify.js):
http://tools.vevb.com/code/js_beautify