이 기사에서는 모바일 액세스 장치를 결정하고 해당 CSS를 구문 분석하기위한 JavaScript 방법을 설명합니다. 참조를 위해 공유하십시오. 특정 분석은 다음과 같습니다.
JavaScript는 주로 모바일 장치에 대한 다양한 웹 액세스 환경을 결정하고 해당 분석 솔루션 (테크 네트워크를 직접 복사하는 장치 코드 판단)을 제공합니다.
다음과 같이 코드를 복사하십시오./ 모바일 운영 환경인지 결정하십시오.
if (/applewebkit.*mobile/i.test (navigator.useragent) || (/midp|symbianos|nokia|samsamsung|lgoinggogow|nec|tcl| alcatel|bird|dbtel| dbtel|dopod| philips| haier| haier| haier| haier | haier | haier | lenovo| mot-| nokia|sonyericsson|sie-asi-asmoi|zte/.test.useragent))))))))) {
if (window.location.href.indexof ( "? mobile") <0) {
노력하다{
if (/android| webos|iphone|ipod| blackberry/i.test (navigator.useragent)) {
// 액세스 환경이 Android | WebOS | iPhone | iPod | BlackBerry인지 확인한 다음 다음 스타일을로드하십시오.
setActiveStyLesheet ( "Style_Mobile_a.css");
}
else if (/ipad/i.test (navigator.useragent)) {
// 액세스 환경이 iPad인지 확인하면 다음 스타일을로드하십시오.
setActiveStyLesheet ( "Style_Mobile_ipad.css");
}
또 다른{
// 액세스 환경이 다른 모바일 장치라고 판단하면 다음 스타일이로드됩니다.
setActiveStyLesheet ( "style_mobile_other.css");
}
}
캐치 (e) {}
}
}
또 다른{
// 위의 내용이없는 경우 다음 스타일
setActiveStyLesheet ( "Style_Mobile_No.css");
}
// 판단 후 스타일로드
함수 setActiveStylesheet (filename) {document.write ( "< 링크 href ="+filename+"rel = stylesheet>");}
로딩 페이지 :
다음과 같이 코드를 복사하십시오. <script type = "text/javaScript">
if (/applewebkit.*mobile/i.test (navigator.useragent) || (/midp|symbianos|nokia|samsamsung|lgoinggogow|nec|tcl| alcatel|bird|dbtel| dbtel|dopod| philips| haier| haier| haier| haier | haier | haier | lenovo| mot-| nokia|sonyericsson|sie-asi-asmoi|zte/.test.useragent))))))))) {
if (window.location.href.indexof ( "? mobile") <0) {
노력하다{
if (/android| webos|iphone|ipod| blackberry/i.test (navigator.useragent)) {
Window.location.href = "모바일 페이지";
} else if (/ipad/i.test (navigator.useragent)) {
Window.location.href = "태블릿 페이지";
}또 다른{
Window.location.href = "기타 모바일 페이지"
}
} catch (e) {}
}
}
</스크립트>
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.