replaceWith pero permanente - otra forma de almacenar

I have a div which I update with a count of contents of a shopping cart - when a user adds to the cart, i count the number of lines, then update the div to say e.g. 2 Lines

Actualmente uso:

<script type="text/javaScript">

I use replace with as I say "0 Items" at the start of a user session.

All works great apart from when user leaves the cart page, the div then changes back to 0 Items - is there a way to rewrite a div more permanently?

I know its a hack but its a favour for a favour thingy!

preguntado el 30 de enero de 12 a las 19:01

what you need is probably galleta. there is no way of making div "permanent" by itself. You can either update part of the page only (AJAX) or store information about products on client's side - the second one is easier and one way to achieve it is by ussing a cookie. By the way, you need to store the information about what items have been added -

Damn, a cookie, of course! Doh! Thanks guys -

2 Respuestas

look into session storage and local storage a little better security wise than cookies overall and is supported on all major browsers, check this example fill in the fields and refresh the browser, check the source code it's pretty straightforward

Respondido el 31 de enero de 12 a las 00:01

It is not possible for jQuery to "write a div more permanently". For items to persist across pages you'd need to set a cookie or a session.

Look into jquery cookie() plugin... this will help accomplish what you are looking to do.

This will help in getting data to persist across pages. Hope this helps.

Respondido el 31 de enero de 12 a las 00:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.