JSは、主にモバイルデバイス用のさまざまなWebアクセス環境を判断し、対応する分析ソリューションを提供します(デバイスコードを直接コピーtencent.com)
コードコピーは次のとおりです。
//モバイルオペレーティング環境かどうかを判断します
if(/applewebkit.*mobile/i.test(navigator.useragent)|| (/midp | symbianos|nokia|samsung| lg|nec|tcl| alcatel|bird| dbtel| dopod| philips| haier| lenovo| mot-mot-nokia-nokiasson|sie- amoi| zte/.test(navigator.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(/pad/i.test(navigator.useragent)){
//アクセス環境がiPadであると判断した場合は、次のスタイルをロードします
setactivestylesheet( "style_mobile_ipad.css");
}
それ以外{
//アクセス環境が別のモバイルデバイスであると判断した場合、次のスタイルがロードされます
setactivestylesheet( "style_mobile_other.css");
}
}
catch(e){}
}
}
それ以外{
//上記のいずれもロードされていない場合、次のスタイル
setactivestylesheet( "style_mobile_no.css");
}
//判断後のスタイルの読み込み
function setactivestylesheet(filename){document.write( "<link href ="+filename+"rel = styleSheet>");}
ページの読み込み
コードコピーは次のとおりです。
<script type = "text/javascript">
if(/applewebkit.*mobile/i.test(navigator.useragent)|| (/midp | symbianos|nokia|samsung| lg|nec|tcl| alcatel|bird| dbtel| dopod| philips| haier| lenovo| mot-mot-nokia-nokiasson|sie- amoi| zte/.test(navigator.useragent)){
if(window.location.href.indexof( "?mobile")<0){
試す{
if(/android|webos|iphone|ipod|blackberry/i.test(navigator.useragent)){
window.location.href = "モバイルページ";
} else if(/pad/i.test(navigator.useragent)){
window.location.href = "tablet page";
}それ以外{
window.location.href = "その他のモバイルページ"
}
} catch(e){}
}
}
</script>