ปัจจุบัน Baidu ให้บริการสคริปต์ JS Webmasters เพื่อตัดสินประเภทของเทอร์มินัลมือถือและกระโดดโดยอัตโนมัติซึ่งช่วยอำนวยความสะดวกส่วนใหญ่ของเว็บมาสเตอร์และนักพัฒนาเว็บ การใช้สคริปต์ JS นั้นง่ายมาก
การคัดลอกรหัสมีดังนี้:
<script src = "http://siteapp.baidu.com/static/webappservice/uaredirect.js" type = "text/javascript"> </script>
<script type = text/javascript> uaredirect ("เว็บไซต์มือถือ", "เว็บไซต์"); </script>
รหัสการจัดรูปแบบสคริปต์ JS หลักที่สุดมีดังนี้:
การคัดลอกรหัสมีดังนี้:
ฟังก์ชั่น uaredirect (f) {
พยายาม {
if (document.getElementById ("bdmark")! = null) {
กลับ
-
var b = false;
ถ้า (อาร์กิวเมนต์ [1]) {
var e = window.location.host;
var a = window.location.href;
if (issubdomain (อาร์กิวเมนต์ [1], e) == 1) {
f = f + "/#m/" + a;
b = true
} อื่น {
if (issubdomain (อาร์กิวเมนต์ [1], e) == 2) {
f = f + "/#m/" + a;
b = true
} อื่น {
f = a;
b = เท็จ
-
-
} อื่น {
b = true
-
ถ้า (b) {
var c = window.location.hash;
if (! c.match ("fromapp")) {
if ((navigator.useragent.match (/(iPhone | iPod | Android | iOS)/i)) {
สถานที่ตั้งอยู่ (F)
-
-
-
} catch (d) {}
-
ฟังก์ชั่น issubdomain (c, d) {
this.getDomain = function (f) {
var e = f.indexof (": //");
ถ้า (e> 0) {
var h = f.substr (e + 3)
} อื่น {
var h = f
-
var g = /^ www/./;
if (g.test (h)) {
H = H.Substr (4)
-
กลับ h
-
ถ้า (c == d) {
กลับ 1
} อื่น {
var c = this.getDomain (c);
var b = this.getDomain (d);
ถ้า (c == b) {
กลับ 1
} อื่น {
c = c.replace (".", "//.");
var a = new regexp ("//." + c + "$");
ถ้า (b.match (a)) {
กลับ 2
} อื่น {
กลับ 0
-
-
-
-
ขอแนะนำให้ผู้ดูแลเว็บและนักพัฒนาเว็บใช้สคริปต์ JS ที่ถูกบีบอัดดังนี้
การคัดลอกรหัสมีดังนี้:
ฟังก์ชั่น uaredirect (f) {ลอง {if (document.getElementById ("bdmark")! = null) {return} var b = false; ถ้า (อาร์กิวเมนต์ [1]) {var e = window.location.host; var; a = window.location.href; if (issubdomain (อาร์กิวเมนต์ [1], e) == 1) {f = f+"/#m/"+a; b = true} อื่น {ถ้า (ISS ubdomain (อาร์กิวเมนต์ [1], e) == 2) {f = f+"/#m/"+a; b = true} อื่น {f = a; b = talse}}} else {b = true} ถ้า (b) {var c = window.location.hash; if (! c.match ("fromapp")) {ถ้า ((navigator.useragent.match (/(iphone | iPod | Android | iOS)/i))) {location.replace (f)}}}}}} catch (d) {}} ฟังก์ชั่น e = f.indexof (": //"); ถ้า (e> 0) {var h = f.substr (e+3)} else {var h = f} var g =/^www /./; ถ้า (g.test (h)) {h = h.substr (4)}}; b = this.getDomain (d); ถ้า (c == b) {return 1} else {c = c.replace (".", "//."); var a = ใหม่ regexp ("//."+ c+" $ "); ถ้า (b.match (a)) {return 2} {return 0}}}}}
PS: ที่นี่บรรณาธิการแนะนำการจัดรูปแบบ JavaScript การจัดรูปแบบความงามและเครื่องมือการบีบอัด คล้ายกับการบีบอัดรหัสกระโดดข้าม Baidu ด้านบนและการจัดรูปแบบคุณสามารถใช้เครื่องมือต่อไปนี้เพื่อนำไปใช้งาน:
C รูปแบบภาษา/HTML/CSS/JSON รหัสการจัดรูปแบบและเครื่องมือเสริมความงาม:
http://tools.vevb.com/code/ccode_html_css_json
เครื่องมือการตกแต่งและการจัดรูปแบบรหัส JavaScript ออนไลน์:
http://tools.vevb.com/code/js
JavaScript Code Beautification/การบีบอัด/การจัดรูปแบบ/เครื่องมือเข้ารหัส:
http://tools.vevb.com/code/jscompress
เครื่องมือการบีบอัด JavaScript ออนไลน์:
http://tools.vevb.com/code/js_yasuo
เครื่องมือการจัดรูปแบบออนไลน์ JavaScript (ขึ้นอยู่กับปลั๊กอิน beautify.js):
http://tools.vevb.com/code/js_beautify