Baidu fournit actuellement des webmasters avec des scripts JS pour juger du type de terminal mobile et sauter automatiquement, ce qui facilite considérablement la majorité des webmasters et des développeurs Web. L'utilisation de son script JS est extrêmement simple.
La copie de code est la suivante:
<script src = "http://siteApp.baidu.com/static/webappService/uaredirect.js" type = "Text / JavaScript"> </ script>
<Script type = text / javascript> uaredirect ("site mobile", "site Web"); </cript>
Le code de formatage de script JS le plus principal est le suivant:
La copie de code est la suivante:
fonction uaredirect (f) {
essayer {
if (document.getElementById ("bdmark")! = null) {
Retour
}
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 = vrai
} autre {
if (issubdomain (arguments [1], e) == 2) {
f = f + "/ # m /" + a;
b = vrai
} autre {
f = a;
b = faux
}
}
} autre {
b = vrai
}
if (b) {
var c = window.location.hash;
if (! C.Match ("FromApp")) {
if ((Navigator.UserAgent.match (/ (iPhone | iPod | Android | iOS) / i)) {
emplacement.replace (f)
}
}
}
} catch (d) {}
}
fonction issubdomain (c, d) {
this.getDomain = fonction (f) {
var e = f.indexof (": //");
if (e> 0) {
var h = f.substr (e + 3)
} autre {
var h = f
}
var g = /^www/./;
if (g.test (h)) {
H = H.Substr (4)
}
Retour h
};
if (c == d) {
retour 1
} autre {
var c = this.getDomain (c);
var b = this.getDomain (d);
if (c == b) {
retour 1
} autre {
c = c.replace (".", "//.");
var a = new regexp ("//." + c + "$");
if (b.match (a)) {
retour 2
} autre {
retour 0
}
}
}
};
Il est recommandé que les webmasters et les développeurs Web utilisent les scripts JS compressés comme suit
La copie de code est la suivante:
fonction 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 {is (ish ubdomain (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) {}} fonction issubdomain (c, D) {this.get 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 = that.get (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}}};
PS: Ici, l'éditeur recommande plusieurs outils de mise en forme, d'embellissement et de compression JavaScript. Semblable à la compression et au formatage du code de saut Baidu ci-dessus, vous pouvez utiliser les outils suivants pour l'implémenter:
C Style de langue C / HTML / CSS / JSON Code Formatage et Outils d'embellissement:
http://tools.vevb.com/code/ccode_html_css_json
Outils d'embellissement et de formatage du code JavaScript en ligne:
http://tools.vevb.com/code/js
Outils d'embellissement / compression / formatage / de formatage du code JavaScript:
http://tools.vevb.com/code/jscompress
Outil de compression en ligne JavaScript:
http://tools.vevb.com/code/js_yasuo
Outil de mise en forme en ligne javascript (basé sur le plugin embeltify.js):
http://tools.vevb.com/code/js_beautify