Back button complicates ASP shopping cart item removal

P

Penny

Hi all,

I've built an online shopping cart using ASP Classic(based on a 'WebThang'
tutorial). The shop cart page (with table showing customers selected items
and costs) has only 3 buttons/links.

1: Back to Shop: Uses 'javascript:history.go(-1)' to go to previous page.

2: Remove Item(one next to each item in cart): Clears the selected item from
the session variable array redisplays the page.

3: Checkout: Proceeds nicely to the pages that collect the customers
details.

My Problem:

If the user clicks the 'Remove Item' link/button, the page efficiently
redisplays with the selected item removed from the list. However, if the
user then clicks either the 'Back to Shop' button or the browser Back button
(intending to continue shopping), the cart page redisplays showing the
removed item back in the list as it was before they removed it. Although the
session variable array remains correctly unaltered it is very confusing to
the user and will probably cause them to feel that their shopping list has
been 'messed up' and is now invalid.

I understand that the browser is just 'doing what it is told' but need to
find a way to avoid this confusing behaviour.

Any ideas,

Regards

Penny.
 
M

Mark J. McGinty

Penny said:
Hi all,

I've built an online shopping cart using ASP Classic(based on a 'WebThang'
tutorial). The shop cart page (with table showing customers selected items
and costs) has only 3 buttons/links.

1: Back to Shop: Uses 'javascript:history.go(-1)' to go to previous page.

2: Remove Item(one next to each item in cart): Clears the selected item
from
the session variable array redisplays the page.

3: Checkout: Proceeds nicely to the pages that collect the customers
details.

My Problem:

If the user clicks the 'Remove Item' link/button, the page efficiently
redisplays with the selected item removed from the list. However, if the
user then clicks either the 'Back to Shop' button or the browser Back
button
(intending to continue shopping), the cart page redisplays showing the
removed item back in the list as it was before they removed it. Although
the
session variable array remains correctly unaltered it is very confusing to
the user and will probably cause them to feel that their shopping list has
been 'messed up' and is now invalid.

I understand that the browser is just 'doing what it is told' but need to
find a way to avoid this confusing behaviour.

If you use location.replace to navigate between pages, the old page gets
replaced in the history stack with the new page, giving you somewhat of an
opportunity to manage what's available to go back to.

-Mark
 
P

Penny

Hi Mark,

Do you have any snippets of code I could see to get a perspective on how
location.replace can be used?

Regards

Penny.
 
J

Jeff Cochran

Hi all,

I've built an online shopping cart using ASP Classic(based on a 'WebThang'
tutorial). The shop cart page (with table showing customers selected items
and costs) has only 3 buttons/links.

1: Back to Shop: Uses 'javascript:history.go(-1)' to go to previous page.

2: Remove Item(one next to each item in cart): Clears the selected item from
the session variable array redisplays the page.

3: Checkout: Proceeds nicely to the pages that collect the customers
details.

My Problem:

If the user clicks the 'Remove Item' link/button, the page efficiently
redisplays with the selected item removed from the list. However, if the
user then clicks either the 'Back to Shop' button or the browser Back button
(intending to continue shopping), the cart page redisplays showing the
removed item back in the list as it was before they removed it. Although the
session variable array remains correctly unaltered it is very confusing to
the user and will probably cause them to feel that their shopping list has
been 'messed up' and is now invalid.

I understand that the browser is just 'doing what it is told' but need to
find a way to avoid this confusing behaviour.

I would think if you coded the shopping cart page to read the session
variables to populate the fileds and prevented caching on the page you
would see the result you want. Perhaps using a pragma:nocache header
would do it, you can use a meta tag for this:

<meta http-equiv="pragma" content="nocache">

There are other ways to disable page caching as well.

Jeff
 
P

Penny

Patrice,

It works in that it prevents previously removed items from the cart being
shown again but when expecting to be redirected back to the last 'shopping'
page it usually says 'Warning: Page has Expired'.

The suggested code:

<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

Seems to prevent redirecting to whatever the previous page was. My catch is
that I want to return to the 'shop' page that directed to the 'cart' page in
the first place but not return to an old version of the 'cart' page itself.
 
P

Penny

Jeff,

<meta http-equiv="pragma" content="nocache"> doesn't work either. It still
allows the page to redirect to the previous version of itself.

Penny.
 
A

Adrienne

Jeff,

<meta http-equiv="pragma" content="nocache"> doesn't work either. It still
allows the page to redirect to the previous version of itself.

Penny.


IIRC the Meta element is controled by the browser and the browser can
disregard it. AFAIK you have to do it server side, eg:
Response.Expires = 60
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top