PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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.
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
<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>