I have a shopping website and I am using javascript to add items to cart. Every time I click on add to cart, it puts the name of the item in a div that represents the cart. I would like to keep the content of the cart on each page, so what I did is:
$("#cartlink").attr("href", "cart.php?app="+tab+"")
Where “tab” is an array containing all the items in the cart. I then use a GET to retrieve the elements of the cart on the cart.php page. But my problem is since I add items in the cart using JS, if the user changes page without clicking on the cart.php?app link, tab will be erased and I have no way to recover “tab”. If the user clicks on the cart.php link, I can use a GET and store the content into a session and then use it on every page.
So I would need a way to memorize the cart content if the user decides not to click cart.php.
Thanks!
You can use
localStorageto store the cart status in JavaScript, and submit it to the server when the user confirms the order.