我有一个响应式的网站建设,主页是多余的移动,我希望能够重定向到一个特定的内部页面。我已经找到了重定向到网站的移动版本的解决方案,但这不起作用,因为我得到一个重定向循环或你不能访问网站上的任何其他页面。
例如,我想重定向:http://www.url.com/home
至
http://www.url.com/portfolio
仅在移动设备上。而且只有一页。
发布于 2014-10-25 02:20:46
在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");
}
发布于 2014-10-27 05:10:24
这可以通过使用一些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");
}
发布于 2014-10-25 02:09:54
如果你使用的是php,有一些库可以做移动检测。谷歌实际上提供了一个:https://code.google.com/p/php-mobile-detect/
在移动设备上,在将任何内容发送到客户端之前,将位置设置为http://www.url.com/portfolio。
如果是javascript,就有点棘手了,但你可以大致了解用户代理,并设置一个变量来选择哪种设备。
What is the best way to detect a mobile device in jQuery?
一旦有了这个变量,您就可以对重定向URL执行document.location。
https://stackoverflow.com/questions/26553645
复制相似问题