تصف هذه المقالة طريقة JavaScript لتحديد جهاز الوصول إلى الأجهزة المحمولة وتحليل CSS المقابل. شاركه للرجوع إليه. التحليل المحدد هو كما يلي:
تحدد JavaScript بيئات وصول ويب مختلفة ، خاصة للأجهزة المحمولة ، وتوفر حلول التحليل المقابلة (تحكم رموز الأجهزة مباشرة نسخ شبكة Tencent):
انسخ الرمز كما يلي:/ تحديد ما إذا كانت بيئة تشغيل للجوال
if (/applewebkit.*mobile/i.test (navigator.useragent) || (/midp|symbianos| nokia| samsung coutnec coutcl coutlcatel coutbirdoutel coutdeddeddopod counseier counovo cout-e inkia coutonericsonericsson- outse-e z ((
if (window.location.href.indexof ("؟ mobile") <0) {
يحاول{
if (/android|webos Oiphone| outblackberry/i.test (navigator.useragent)) {
// حدد أن بيئة الوصول هي Android | Webos | iPhone | iPod | BlackBerry ، ثم قم بتحميل النمط التالي
SetActivestylesHeet ("style_mobile_a.css") ؛
}
آخر إذا (/ipad/i.test (navigator.useragent)) {
// إذا حددت أن بيئة الوصول هي iPad ، فقم بتحميل النمط التالي
SetActivestylesheet ("style_mobile_ipad.css") ؛
}
آخر{
// إذا حددت أن بيئة الوصول هي جهاز محمول آخر ، فسيتم تحميل النمط التالي
SetActivestylesheet ("style_mobile_other.css") ؛
}
}
catch (e) {}
}
}
آخر{
// إذا لم يتم تحميل أي مما سبق ، فإن النمط التالي
SetActivestylesheet ("style_mobile_no.css") ؛
}
// نمط التحميل بعد الحكم
وظيفة setActivestylesheet (fileName) {document.write ("< Link Href ="+filename+"rel = stylesheet>") ؛}
صفحة التحميل:
انسخ الرمز كما يلي: <script type = "text/javaScript">
if (/applewebkit.*mobile/i.test (navigator.useragent) || (/midp|symbianos| nokia| samsung coutnec coutcl coutlcatel coutbirdoutel coutdeddeddopod counseier counovo cout-e inkia coutonericsonericsson- outse-e z ((
if (window.location.href.indexof ("؟ mobile") <0) {
يحاول{
if (/android|webos Oiphone| outblackberry/i.test (navigator.useragent)) {
window.location.href = "mobile page" ؛
} آخر إذا (/ipad/i.test (navigator.useragent)) {
window.location.href = "tablet page" ؛
}آخر{
window.location.href = "صفحات متنقلة أخرى"
}
} catch (e) {}
}
}
</script>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.