这以一种方式,它将记住用户选择 100 天。
http://www.w3schools.com/js/js_cookies.asp
使用我提供的链接中的功能:然后更改此如果;
<script type="text/javascript">
<!--
if (screen.width <= 700 && getCookie("mobileRedirected")!="true"){
window.location = "http://domain.com";
}
//-->
</script>
在返回该页面的链接上执行以下操作:
<a href="#" onclick="setCookie('mobileRedirected','true',100);document.location='index.html';">LINK</a>
下次用户开始索引时,它会知道它已经点击了离开 mobile.html 的方式
也就是说,如果您希望用户能够在站点之间进行选择,如果没有(仅显示移动设备一次),您可以这样做:
<script type="text/javascript">
<!--
if (screen.width <= 700 && getCookie("mobileRedirected")!="true"){
setCookie('mobileRedirected','true',100);
window.location = "http://domain.com";
}
//-->
</script>
并一起跳过链接代码
上面代码的完整工作示例
<script type="text/javascript">
function setCookie(c_name,value,exdays){
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++){
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name) {
return unescape(y);
}
}
}
if (screen.width <= 700 && getCookie("mobileRedirected")!="true"){
setCookie('mobileRedirected','true',100);
window.location = "http://google.com";
}
</script>
如果您希望小型浏览器窗口也被重定向,您也可以使用 window.innerWidth。工作示例链接:http ://allanthya.net/cookietest.php