Page 1 of 1

clear shopping cart content on body unload or browser exit

Posted: Mon Nov 03, 2008 11:38 pm
by vinpkl
hi all

i am looking for a function that clears the contents of the shopping cart on closing the browser or browser exit and displays an confirm alert before removing the contents.

i have a script that clear contents on clicking the clear cart button but i need to have the same option on closing the browser or browser exit.

this is my script

Code: Select all

 
if(isset($_REQUEST['clear_cart_x']))
{
$product_id=$row['product_id'];
$image=$row['image'];
$product_name=$row['product_name'];
$price=$row['price'];
$shipping_cost=$row['shipping_cost'];
$quantity=$row['quantity'];
$total_cost=$row['total_cost'];
$qry="delete from cart_table where unique_id='$unique_id'";
mysql_query($qry);
}
 
vineet

Re: clear shopping cart content on body unload or browser exit

Posted: Tue Nov 04, 2008 3:15 pm
by Jade
You'll need to use javascript on body unload to call the URL of that file. That way every time the window is closed, your php script runs and clears everything out.

Re: clear shopping cart content on body unload or browser exit

Posted: Tue Nov 04, 2008 9:34 pm
by vinpkl
Jade wrote:You'll need to use javascript on body unload to call the URL of that file. That way every time the window is closed, your php script runs and clears everything out.
hi jade

thanks for the reply. I got a example code from this site, can u tell me where to add the url of that file as this code will come in all my pages because user can exit from any page.
My php file name is shopping_cart.php

Code: Select all

 
<html>
<head>
<script language="JavaScript">
function redAlert() 
{
confirm("Are you sure you want to leave this Web page?");
}
</script>
</head>
<body onUnload="redAlert()">
</body>
</html>
 
vineet