我在重定向到我的移动版本时遇到了问题。我没有足够的编程技巧来完成这个任务。我被卡住了。
下面是我下面的代码,但首先是我想要完成的逻辑:
就是这样,但我不能让它起作用。
下面是我放置在标题中的代码:
<script type="text/javascript">
<!--
var fullSiteCookie = readCookie('fullsite');
if ( fullSiteCookie !='t' ) {
if (screen.width <= 600) {
window.location = "/m/mobile.html";
}
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
document.location = "/m/mobile.html";
}
if ( (navigator.userAgent.indexOf('iphone') != -1) ) {
document.location = "/m/mobile.html";
}
else
document.location="/";
}
//-->
</script>然后,整个站点上的超链接是:
<a href="/m/mobile.html" onclick="writeCookie('fullsite', 'm')">View Mobile Site</span></a>同样,移动站点也有自己的链接:
<a href="../index.php" onClick="writeCookie('fullsite', 't')">FULL SITE VERSION</a>问题:我永远无法让网站(第一次)转到移动版本。它只适用于完整的桌面版本。这是个阻止表演的地方。如果访问者正在移动设备上访问该站点,则必须能够自动将其发送到该移动站点。不需要单击任何内容。
有什么想法吗?在没有帮助的情况下,我将无法解决这个问题。当然,这是我昨天需要的东西。
发布于 2014-08-24 23:09:11
您的else放在if中,它只在非iPhone条件下触发。试试这个:
if ( fullSiteCookie !='t' ) {
if (fullSiteCookie =='m' || screen.width <= 600 || navigator.userAgent.indexOf('Android') != -1 || navigator.userAgent.indexOf('iphone') != -1) {
window.location = "/m/mobile.html";
} else {
// not mobile or forced mobile
document.location = "/";
}
} else {
// forced Normal
document.location = "/";
}发布于 2014-08-24 23:27:17
类似于“忠诚度科技”的建议,但我有一些要补充。
var fullSiteCookie = readCookie('fullsite');
/* Verify that "fullSiteCookie" is a valid value.
Are you sure the cookie is set the first time?
*/
if ( fullSiteCookie !='t' &&
(screen.width <= 600 ||
navigator.userAgent.indexOf('Android') != -1 ||
/* Fix case of "iphone" to "iPhone" */
navigator.userAgent.indexOf('iPhone') != -1)){
window.location = "/m/mobile.html";
} else {
window.location = "/";
}https://stackoverflow.com/questions/25477061
复制相似问题