現在做網站除了使用RWD的方式外,還會使用js來判斷使用者究竟是用pc連過來網站還是手機或平板電腦,這段code我還蠻常用的,分享給需要用js做device判斷的的網頁設計使用者們
It is a easy way to detect mobile or pc browser
//JavaScript Document
//is it mobile???
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)){
// return mobile true
document.location.href="mobile/index_mobile.html";}else {
//return mobile false go to basic pc site
window.open('PC/index.html','_self');
}}
//執行detectmob function
detectmob();
It is a easy way to detect mobile or pc browser
//JavaScript Document
//is it mobile???
function detectmob() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)){
// return mobile true
document.location.href="mobile/index_mobile.html";}else {
//return mobile false go to basic pc site
window.open('PC/index.html','_self');
}}
//執行detectmob function
detectmob();
如果覺得我的文章有幫助
請你點右邊的FB加入訂閱 我會在粉絲團不定期分享新資訊
也歡迎交流!謝謝 阿特底賽粉絲團
https://www.facebook.com/artdesigntw
No comments:
Post a Comment