偵測手機瀏覽器,並跳到適合的手機網頁

找了一整個下午終於找到可以正確跑的版本,直接貼在原本桌面版網頁的</head> 跟 <body> 之間
更改 default_vector.php 為你需要用的手機版網頁就好囉 (這版本適合html跟php)

感謝黯雲老師!!
ps. 有新裝置就直接新增user agent在ipad後頭即可

 

<script type="text/javascript">

var mobiles = new Array
(
“midp", “j2me", “avant", “docomo", “novarra", “palmos", “palmsource",
“240×320″, “opwv", “chtml", “pda", “windows ce", “mmp/",
“blackberry", “mib/", “symbian", “wireless", “nokia", “hand", “mobi",
“phone", “cdm", “up.b", “audio", “sie-“, “sec-“, “samsung", “htc",
“mot-“, “mitsu", “sagem", “sony", “alcatel", “lg", “eric", “vx",
“NEC", “philips", “mmm", “xx", “panasonic", “sharp", “wap", “sch",
“rover", “pocket", “benq", “java", “pt", “pg", “vox", “amoi",
“bird", “compal", “kg", “voda", “sany", “kdd", “dbt", “sendo",
“sgh", “gradi", “jb", “dddi", “moto", “iphone", “android",
“iPod", “incognito", “webmate", “dream", “cupcake", “webos",
“s8000″, “bada", “googlebot-mobile", “ipad"
)

var ua = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i = 0; i < mobiles.length; i++) {
if (ua.indexOf(mobiles[i]) > 0) {
isMobile = true;
location.href = “default_vector.php"
break;
}
}
</script>

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: