Home > Web Front-end > JS Tutorial > How to determine the mobile access device and parse the corresponding CSS using javascript_javascript skills

How to determine the mobile access device and parse the corresponding CSS using javascript_javascript skills

WBOY
Release: 2016-05-16 16:15:46
Original
1145 people have browsed it

The example in this article describes how javascript determines the mobile access device and parses the corresponding CSS. Share it with everyone for your reference. The specific analysis is as follows:

Javascript determines different web access environments, mainly for mobile devices, and provides corresponding analysis solutions (the device code is directly copied from Tencent):

Copy code The code is as follows:
// Determine whether it is a mobile operating environment
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT- |Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
// If the access environment is Android|webOS|iPhone|iPod|BlackBerry, load the following style
setActiveStyleSheet("style_mobile_a.css");
}
else if(/iPad/i.test(navigator.userAgent)){
// If the access environment is iPad, load the following style
setActiveStyleSheet("style_mobile_iPad.css");
}
else{
// If the access environment is other mobile devices, load the following style
setActiveStyleSheet("style_mobile_other.css");
}
}
catch(e){}
}
}
else{
// If none of the above, load the following styles
setActiveStyleSheet("style_mobile_no.css");
}
//Load the style after the judgment is completed
function setActiveStyleSheet(filename){document.write("

Loading page:

Copy code The code is as follows:


I hope this article will be helpful to everyone’s JavaScript programming design.
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template