Link to home
Start Free TrialLog in
Avatar of jennyd
jennyd

asked on

If a user closes the browser can you bring up a prompt to remind them they have items in the shopping cart?

If a user closes the browser can you bring up a prompt to remind them they have items in the shopping cart?  The user should be able to answer a "Do you really want to close the browser and lose the contents of your shopping cart?" question.  On selecting no the browser would not close on selecting yes the browser would close.  Can anyone please help????
Avatar of CJ_S
CJ_S
Flag of Netherlands image

you could bring the popup there, but you cannot prevent the user from closing his / her browser...
ASKER CERTIFIED SOLUTION
Avatar of hpchong7
hpchong7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hpchong7
hpchong7

This works in netscape.But the items in shopping cart may also disappear.
<BODY onUnload="window.open(location,'_blank');">

The only problem is that onUnload is triggered for a lot more events than just close.  Like changing urls by following a link, choosing a bookmark, clicking the home button.  Also simply hitting reload triggers the onUnload event.  This makes a avery annoying page that just won't go away!  If someone did that to me, I'd definitely never come back!

Now there may be another solution to this that's possible.
There is a property of window objects called closed.  You can test this via another window to determine if the window had been closed.

So you could do something like this in the page which you want to keep it from being closed:
<BODY onLoad="new_win=window.open('test_close.html','test_close','width=100,height=100'); new_win.opener=self; new_win.myURL=location.href;" onUnload="new_win.test_close();">


And then in the test_close.html page, you simply put this code:
function test_close()
{if (opener.closed) //if it's been closed
  window.open(myURL,'_blank');
 else
  setTimeout('test_close()',1000);
}


The only problem is that the user can just close the new window you opened.  If you had another window which you expect to stay open, you could use that instead, and it would have a better chance than a blank window the user doesn't know the purpose for.

listening
Jennyd:does my answer fit you?