我如何重定向到移动设备,但让用户从那时开始切换
How do I redirect to mobile, but let the user switch from then on?
我遇到了一个问题,重定向到我的移动版本。我没有编程技能来完成这个任务。我卡住了。
下面是我的代码,但首先这里是我想要完成的逻辑:
- 手机用户访问时,默认使用手机版本。
- 如果他们点击"查看完整的网站",然后它切换并停留在完整的网站,直到,只有如果他们点击查看移动版本(页脚),然后它停留在移动版本,除非他们再次点击"查看完整的网站"。
就是这样,但是我不能使它工作。
下面是我放在头文件中的代码:
<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>
问题:我永远无法让网站(第一次)转到移动版本。它只适用于完整的桌面版本。那是一场精彩的表演。它必须能够自动发送访问者到移动网站,如果他们正在访问一个移动设备上的网站。不应该点击任何东西。
任何想法?没有别人的帮助,我无法解决这个问题。当然,这是我昨天就需要的东西。
您的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 = "/";
}
类似于@Loyalty Tech的建议,但我有一些要补充。
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 = "/";
}
相关文章:
- 根据用户从下拉列表中的选择显示多个文本框
- 计算用户从多个文件中选择的选项数量
- 如何强制用户从下拉列表和按钮中选择一个值以启用保存按钮
- 根据用户从jQuery UI可选下拉框中选择的内容创建链接
- 如何将用户从jquery移动窗体键入的查询SQL发布到WCF服务,并在WCF服务上运行该查询
- 允许用户从链接下载文件,如果他们选中“;同意条款”;框或单选按钮
- 如何阻止用户从同一浏览器中的不同选项卡同时登录
- 当用户从下拉列表中选择时刷新 CKEDITOR
- 当用户从页面底部达到 X 像素时,如何显示 DIV
- 如何阻止用户从浏览器控制台更改脚本
- 如何在输入错误的用户名和/或密码时将用户从登录控件重定向到错误页面
- 当用户从下拉列表中选择值时,如何在文本字段中显示数据库值
- 当用户从另一个选项卡注销谷歌时,如何执行一些javascript
- ASP.NET将用户从服务器注销
- 当用户从后退按钮到达时重新加载页面
- 通知我网站的android用户从网站安装android应用程序
- HTML强制用户从URL下载PDF文件
- 强制用户从下拉框中进行选择
- 阻止用户从地址栏复制URL
- 我如何重定向到移动设备,但让用户从那时开始切换