Firefox下利用Cookies出现跨二级域名不能提交购物车信息

Firefox下出现跨二级域名不能提交购物车信息

(问题在http://space.cnblogs.com/question/20513/

  主域名  www.MySite.com

  商品目录  www.MySite.com/mall

 结算目录   member.MySite.com 

  用户在 主域名www.MySite.com  加入购物车的商品能在 商品目录  www.MySite.com/mall显示,在ie下能在 结算目录   member.MySite.com 显示进行结算,但在Firefox下却 显示购物车为空,但在

结算目录   member.MySite.com 下ie和Firefox都可以将商品加入购物车,进行结算。

 

下面是 加入购物车和显示购物车的代码,有做过类似的园友们给点意见,O(∩_∩)O谢谢了 
 

 加入购物车
 
    
public void FToCart(imageURL, productID, count, prdouctName)
{
if (imageURL != null && imageURL != '' ) {

if (GetCookie( ' imageURL ' ) != null ) {
var ar
= GetCookie( ' imageURL ' ).split( ' # ' )
var cook
= '' ;

for (var i = ar.length - 1 ; i >= 0 ; i -- ) {
if (ar[i] != imageURL) {
if (cook != '' ) {
cook
= ar[i] + ' # ' + cook;
}
else {
cook
= ar[i];
}
}
}
if (cook != "" )
imageURL
+= " # " + cook
}
SetCookie(
' imageURL ' , imageURL)

var cook
= GetCookie( ' count ' );
if (cook != null ) {
if (cook != '' ) {
cook
= cook + ' # ' + count;
}
else {
cook
= count;
}
}
else
cook
= count;
SetCookie(
' count ' , cook)
}

if (productID != null && productID != '' ) {

if (GetCookie( ' productID ' ) != null ) {
var arp
= GetCookie( ' productID ' ).split( ' # ' )
var cookp
= '' ;

for (var i = arp.length - 1 ; i >= 0 ; i -- ) {
if (arp[i] != productID)
if (cookp != '' ) {
cookp
= arp[i] + ' # ' + cookp;
}
else {
cookp
= arp[i]
}
}
if (cookp != "" )
productID
+= " # " + cookp
}

SetCookie(
' productID ' , productID)
}


if (prdouctName != null && prdouctName != '' ) {

if (GetCookie( ' prdouctName ' ) != null ) {
var arn
= GetCookie( ' prdouctName ' ).split( ' # ' )
var cookn
= arn[arn.length - 1 ];

for (var i = arn.length - 2 ; i >= 0 ; i -- ) {
if (arn[i] != prdouctName)
if (cookn != '' ) {
cookn
= arn[i] + " # " + cookn;
}
else {
cookn
= arn[i]
}
}
if (cookn != "" )
prdouctName
+= " # " + cookn
}
SetCookie(
' prdouctName ' , prdouctName)
}
}
显示购物车
 
    
function headshowcart()
{
var arrproductID
= "" ;
arrproductID
= GetCookie( ' productID ' ) == null ? 0 : GetCookie( ' productID ' ).split( ' # ' ).length;
var head_html;
if (objarr[ " cart " ] != null )
{
head_html
= " <div id='showtitle' οnmοuseοver='out1(event,1)' οnmοuseοut='out1(event,2)'><span class='icon'><img src='http://www.MySite.com/public/headfootimg/cart.png'></span> " ;
head_html
+= " <span><a href='http://member.MySite.com/shoppingcart.aspx' style='color:white;'>购物车有 " + arrproductID + " 种商品</a></span></div> " ;
head_html
+= " <div class='head_myorder'><span class='icon2'><img src='http://www.MySite.com/public/headfootimg/wddd.png' /></span> <span><a href='http://member.MySite.com/myorders.aspx' style='color:white;'>我的订单</a></span></div> " ;
objarr[
" cart " ].innerHTML = head_html;
}
// 显示购物车内容

var head_buy
= "" ;
if (objarr[ " showBox " ] != null )
{

if (arrproductID == 0 )
{
head_buy
= " <span style='margin-bottom:5px;'><b>购物车中暂时没有商品</b></span> " ;
objarr[
" showBox " ].style.height = " 30px " ;
}
else
{
var arp_i
= GetCookie( ' productID ' ).split( ' # ' );
var arp_n
= GetCookie( ' prdouctName ' ).split( ' # ' );
var arp_c
= GetCookie( ' count ' ).split( ' # ' );


objarr[
" showBox " ].style.height = 40 * arp_i.length + 27 + " px " ;
for (var i = 0 ; i <= arp_i.length - 1 ; i ++ )
{
var realname
= arp_n[i].replace( ' [ ' , ' < ' );
realname
= realname.replace( ' ] ' , ' > ' );

head_buy
+= " <div class='head_cname'><a href='/mall/product- " + arp_i[i] + " .html' title=' " + realname + " '> " + realname + " </a></div><div class='head_count'><font color='red'>&nbsp;x&nbsp; " + arp_c[i] + " 件</font>&nbsp;&nbsp;<a οnclick=\ " deleteSingle( " +arp_i[i]+ " ); headshowcart();\ " style='cursor:pointer;'>删除</a></div> "
head_buy
+= " <div style='border-top:1px solid #ccc; height:1px;width:300px;'></div> " ;
}
head_buy
+= " <div style='margin-top:5px;float:right; margin-right:5px;'><img src='http://member.MySite.com/images/icon-cart-3.gif' οnclick=' location.href=\ " http: // member.MySite.com/shoppingcart.aspx\"' style='cursor: pointer' /></div>";
}

objarr[
" showBox " ].innerHTML = head_buy;

}

if (objarr[ " wecInfo " ] != null )
{
if (GetCookie( ' www.MySite.com ' ) != null & GetCookie( ' www.MySite.com ' ) != "" ) {
var username
= GetCookie( ' www.MySite.com ' ).split( ' # ' )[ 1 ];
objarr[
" wecInfo " ].innerHTML = " 您好!<span class='STYLE1'> " + username + " ,</span>欢迎光临<a href='http://member.MySite.com/loginout.aspx'><span class='STYLE1'>[退出]</span></a> " ;
}
}
else
{
objarr[
" wecInfo " ].innerHTML = " 您好,欢迎光临!<span class='STYLE1' ><a href='http://member.MySite.com/memberlogin.aspx?PageBack= " + location.href + " ' target='_blank'>[登录]</a></span> <span class='STYLE1'><a href='http://member.MySite.com/memberlogin.aspx?PageBack= " + location.href + " ' target='_blank'>[免费注册]</a></span> " ;
}

}

 

设定Cookie值
 
    
function SetCookie(name, value)
// 设定Cookie值
{
var Days
= 30 ; // 此 cookie 将被保存 30 天
var exp = new Date(); // new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000 );
var domain
= " .MySite.com " ;
document.cookie
= name + " = " + escape(value) + " ;expires= " + exp.toGMTString() + " ;path=\;domain= " + domain;
}

 

获得Cookie的原始值
 
    
function GetCookie(name)
// 获得Cookie的原始值
{
var arg
= name + " = " ;
var alen
= arg.length;
var clen
= document.cookie.length;
var i
= 0 ;
while (i < clen) {
var j
= i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal(j);
i
= document.cookie.indexOf( " " , i) + 1 ;
if (i == 0 ) break ;
}
return null ;
}

 

 

(回答问题http://space.cnblogs.com/question/20513/

 

 

转载于:https://www.cnblogs.com/codemo/archive/2010/12/01/1892686.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值