简体   繁体   中英

Javascript window.open() more than once to add item to cart

     $.each(sizeSkuID,function(key,val){
        var sizeSkuSplit= val.split("-");
        var url="http://www.hostname.com/cart/add/?p="+sizeSkuSplit[0]+"&sku="+val;

        window.open(url,"cart");


    });

I thought I could add multiple item into cart by executing multiple window.open but the above code loop 2 item but it add only the 2nd item in the cart.

If I emulate by clicking one by one (selecting 1 item) at the time using the above code, the cart will have two item in the end.

So why if it loop two time, the window.open apparently run once and it takes the 2nd url?

It's because you taget the same window ( cart ).

say:

window.open(url,"cart" + key);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM