【发布时间】:2015-01-13 16:04:31
【问题描述】:
我收到警报,当使用 safari/ios 将商品放入我们的购物车时,它们没有出现。未设置购物车 cookie。它由重定向页面设置。我看到了关于 safari 没有设置 cookie 和重定向的问题,但是如果我取出重定向,它仍然没有设置。这是代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>
<script type="text/javascript">window.onload= function() {
SetCookie('RORDERID','OECLICK*17180*39521',10);
setTimeout("redir()",100);}
function redir(){window.location = 'http://www.shopthethirdfloor.com/forward-to-ttf-cart.html';}
function SetCookie(cookieName,cookieValue,nDays) {var today = new Date();var expire = new Date();
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();}</script>
</head>
<body><br>If you are not redirected to the shopping cart, <a href="http://www.THESITE.com/forward-to-ttf-cart.html">click here</a></body></html>
我认为 setTimeout 可能会允许它工作,但如果我取消对 redir() 的调用,它仍然不会设置 cookie。
有什么建议吗?
补充说明:我找到了一篇关于这个的帖子,并将代码更新为:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>
<script type="text/javascript">window.onload= function() {
setCookie2('RORDERID','OECLICK*17180*43',10,'','','');
//setTimeout("redir()",100);
}
function redir(){window.location = 'http://www.shopthethirdfloor.com/forward-to-ttf-cart.html';}
function setCookie2 (name, value, nDays, path, domain, secure) {var today = new Date();var expires = new Date();
expires.setTime(today.getTime() + 3600000*24*nDays);
var curCookie = name + "=" + encodeURIComponent(value) + (expires ? "; expires=" + expires.toGMTString() : "") + (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
document.cookie = curCookie;}</script>
</head>
<body><br>If you are not redirected to the shopping cart, <a href="http://www.thesitename.com/forward-to-ttf-cart.html">click here</a></body></html>
它可以工作,但仍然无法在我的网站上工作。此代码正在我网站上不同域的 iframe 中运行。该网站是 www.shopthethirdfloor.com。如果您转到产品,选择一个产品并将其添加到购物车中,它不会在 safari 上添加 cookie,但会在其他浏览器上添加。
【问题讨论】:
标签: javascript safari mobile-safari