DIV CSS 佈局教程網

如何判斷瀏覽器是 PC 還是行動裝置?
編輯:JavaScript基礎知識     

用 navigator.platform 初判裝置

過去常透過 navigator.platform 判斷 Win、Mac、Linux 等平台,再導向電腦版或行動版頁面。

var system = {
  win: false,
  mac: false,
  xll: false
};
var p = navigator.platform;
system.win = p.indexOf('Win') === 0;
system.mac = p.indexOf('Mac') === 0;
system.xll = p === 'X11' || p.indexOf('Linux') === 0;
if (system.win || system.mac || system.xll) {
  window.location.href = 'https://hovertree.com/url/?h=https://hovertree.net/';
} else {
  window.location.href = './appweb.html';
}

實務上仍建議搭配 User-Agent、視窗寬度與功能偵測,避免單一判斷造成誤導。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved