JS julga diferentes ambientes de acesso à web, principalmente para dispositivos móveis, e fornece soluções de análise correspondentes (Judging Codes de dispositivos Copiar diretamente tencent.com)
A cópia do código é a seguinte:
// determinar se é um ambiente operacional móvel
if (/applewebkit.*mobile/i.test (Navigator.UserAgent) || (/MIDP|SyMBIANOS|NOKIA|Samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|filips| heier| lenovo|Mot-|Nokia|SonyericSson|sie-lamoi)-)-
if (window.location.href.indexof ("? Mobile") <0) {
tentar{
if (endroid| webos|iphone|ipod|blackberry/i.test (Navigator.UserAgent)) {
// determinar que o ambiente de acesso é Android | webos | iPhone | ipod | BlackBerry e, em seguida, carregue o seguinte estilo
setActiveStySheetheet ("style_mobile_a.css");
}
caso contrário, se (/ipad/i.test (Navigator.UserAgent)) {
// Se você determinar que o ambiente de acesso é iPad, carregue o seguinte estilo
setActiveStySheetheet ("style_mobile_ipad.css");
}
outro{
// Se você determinar que o ambiente de acesso é outro dispositivo móvel, o seguinte estilo será carregado
SetActiveStySheetheet ("style_mobile_other.css");
}
}
Catch (e) {}
}
}
outro{
// Se nenhuma das opções acima for carregada, o seguinte estilo
SetActiveStySheetheet ("style_mobile_no.css");
}
// estilo de carregamento após julgamento
função setActiveStySheetheet (nome do arquivo) {document.write ("< link href ="+nome do arquivo+"rel = stylesheet>");}
Carregando a página
A cópia do código é a seguinte:
<script type = "text/javascript">
if (/applewebkit.*mobile/i.test (Navigator.UserAgent) || (/MIDP|SyMBIANOS|NOKIA|Samsung|lg|nec|tcl|alcatel|bird|dbtel|dopod|filips| heier| lenovo|Mot-|Nokia|SonyericSson|sie-lamoi)-)-
if (window.location.href.indexof ("? Mobile") <0) {
tentar{
if (endroid| webos|iphone|ipod|blackberry/i.test (Navigator.UserAgent)) {
window.Location.href = "Página móvel";
} else if (/ipad/i.test (Navigator.UserAgent)) {
window.Location.href = "Página do tablet";
}outro{
window.Location.href = "Outras páginas móveis"
}
} catch (e) {}
}
}
</script>