【问题标题】:Redirect Specific URL to another URL on moblile only仅在移动设备上将特定 URL 重定向到另一个 URL
【发布时间】:2014-10-24 18:01:03
【问题描述】:
【问题讨论】:
标签:
javascript
php
html
mobile
responsive-design
【解决方案1】:
将此代码插入http://www.url.com/home 文件
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}};
if( isMobile.any() ) {
window.location.assign("http://www.url.com/portfolio");
}
【解决方案2】:
这可以通过使用一些 JavaScript 轻松实现。 if 语句中的代码检测用户是否使用移动设备(Android、iOS、Kindle、BlackBerry、Windows Phone、Kindle 等),if 语句中的代码只是将用户重定向到您指定的链接。
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|BB|PlayBook|IEMobile|Windows Phone|Kindle|Silk|Opera Mini/i.test(navigator.userAgent)) {
window.location.replace("http://www.url.com/portfolio");
}