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????
you could bring the popup there, but you cannot prevent the user from closing his / her browser...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This works in netscape.But the items in shopping cart may also disappear.
<BODY onUnload="window.open(loca tion,'_bla nk');">
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.ope n('test_cl ose.html', 'test_clos e','width= 100,height =100'); new_win.opener=self; new_win.myURL=location.hre f;" onUnload="new_win.test_clo se();">
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.
<BODY onUnload="window.open(loca
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.ope
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()',
}
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?