Baiduは現在、Mobile端末の種類を判断し、自動的にジャンプするJSスクリプトをWebマスターに提供し、大半のWebマスターとWeb開発者を大幅に促進します。 JSスクリプトの使用は非常に簡単です。
コードコピーは次のとおりです。
<Script src = "http://siteapp.baidu.com/static/webappservice/uaredirect.js" type = "text/javascript"> </script>
<script type = text/javascript> uaredirect( "モバイルサイト"、 "webサイト"); </script>
最もコアJSスクリプトフォーマットコードは次のとおりです。
コードコピーは次のとおりです。
functionuaredirect(f){
試す {
if(document.getElementById( "bdmark")!= null){
戻る
}
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
} それ以外 {
if(issubdomain(arguments [1]、e)== 2){
f = f + "/#m/" + a;
b = true
} それ以外 {
f = a;
b = false
}
}
} それ以外 {
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){}
}
関数issubdomain(c、d){
this.getDomain = function(f){
var e = f.indexof( "://");
if(e> 0){
var h = f.substr(e + 3)
} それ以外 {
var H = f
}
var g = /^www/./;
if(g.test(h)){
H = H.Substr(4)
}
hを返します
};
if(c == d){
返品1
} それ以外 {
var c = this.getDomain(c);
var b = this.getdomain(d);
if(c == b){
返品1
} それ以外 {
c = c.Replace( "。"、 "//。");
var a = new regexp( "//。" + c + "$");
if(b.match(a)){
戻る2
} それ以外 {
0を返します
}
}
}
};
ウェブマスターとウェブ開発者が次のように圧縮されたJSスクリプトを使用することをお勧めします
コードコピーは次のとおりです。
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(iss 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){}} fuctunce issubdomain(c、d)bar. 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 hut}; if. b = this.getdomain(d); if(c == b){return 1} else {c = c.replace( "
PS:ここで、編集者はいくつかのJavaScriptのフォーマット、美化、および圧縮ツールを推奨しています。上記のBaiduジャンプコードの圧縮とフォーマットと同様に、次のツールを使用して実装できます。
C言語スタイル/HTML/CSS/JSONコードのフォーマットおよび美化ツール:
http://tools.vevb.com/code/ccode_html_css_json
オンラインJavaScriptコードの美化とフォーマットツール:
http://tools.vevb.com/code/js
JavaScriptコードの美化/圧縮/フォーマット/暗号化ツール:
http://tools.vevb.com/code/jscompress
JavaScriptオンライン圧縮ツール:
http://tools.vevb.com/code/js_yasuo
JavaScriptオンラインフォーマットツール(beautify.jsプラグインに基づく):
http://tools.vevb.com/code/js_beautify