Atualmente, o Baidu fornece aos webmasters scripts JS para julgar o tipo de terminal móvel e saltar automaticamente, o que facilita bastante a maioria dos webmasters e desenvolvedores da Web. O uso de seu script JS é extremamente simples.
A cópia do código é a seguinte:
<script src = "http://siteApp.baidu.com/static/webappservice/uedirect.js" type = "text/javascript"> </script>
<Script type = text/javascript> uedirect ("site móvel", "site"); </script>
O código de formatação de script mais central do JS é o seguinte:
A cópia do código é a seguinte:
função uedirect (f) {
tentar {
if (document.getElementById ("bdmark")! = null) {
Retornar
}
var b = false;
if (argumentos [1]) {
var e = window.Location.host;
var a = window.location.href;
if (IssubDomain (argumentos [1], e) == 1) {
f = f + "/#m/" + a;
b = verdadeiro
} outro {
if (iSsubDomain (argumentos [1], e) == 2) {
f = f + "/#m/" + a;
b = verdadeiro
} outro {
f = a;
b = falso
}
}
} outro {
b = verdadeiro
}
if (b) {
var c = window.Location.hash;
if (! C.Match ("FromApp")) {
if ((Navigator.UserAgent.Match (/(iPhone | ipod | Android | iOS)/i)) {
Location.Place (F)
}
}
}
} catch (d) {}
}
função isSubDomain (c, d) {
this.getDomain = function (f) {
var e = f.indexOf (": //");
if (e> 0) {
var h = f.substr (e + 3)
} outro {
var h = f
}
var g = /^www/./;
if (g.test (h)) {
H = H.Substr (4)
}
Retornar h
};
if (c == d) {
retornar 1
} outro {
var c = this.getDomain (c);
var b = this.getDomain (d);
if (c == b) {
retornar 1
} outro {
c = c.Replace (".", "//.");
var a = novo regexp ("//." + c + "$");
if (b.match (a)) {
retornar 2
} outro {
retornar 0
}
}
}
};
Recomenda -se que webmasters e desenvolvedores da Web usem os scripts JS compactados da seguinte maneira
A cópia do código é a seguinte:
function uedirect (f) {tente {if (document.getElementById ("bdmark")! = null) {return} var b = false; if (argumentos [1]) {var e = window.Location.host; 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 = 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)}}}}}} (d) {}} IsSDOMOIN (C) (d) 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.subs (4)} retorn h}; if (c = c = c = d) {d) {d) {d) {d) {d) {d) {d) {d) {d) {d) {h.subs 1)}}; b = this.getDomain (d); if (c == b) {return 1} else {c = c.replace (".", "//."); var a = new regexp ("//."+ c+" $ "); if (b.match (a)) {return 2} {return 0}}};
PS: Aqui, o editor recomenda várias ferramentas de formatação, embelezamento e compressão JavaScript. Semelhante à compactação e formatação do código de salto do Baidu acima, você pode usar as seguintes ferramentas para implementá -lo:
C estilo de idioma/html/css/json formatação e ferramentas de embelezamento:
http://tools.vevb.com/code/ccode_html_css_json
Ferramentas de embelezamento e formatação de código JavaScript on -line:
http://tools.vevb.com/code/js
Ferramentas de embelezamento/formatação/formatação/criptografia JavaScript Code:
http://tools.vevb.com/code/jscompress
Ferramenta de compactação online JavaScript:
http://tools.vevb.com/code/js_yasuo
Ferramenta de formatação on -line JavaScript (baseada no plug -in belinfy.js):
http://tools.vevb.com/code/js_beautify