View Full Version : How to find out if a link was opened in a new window?
ConfusedOfLife
09-06-2002, 01:09 AM
Hi, I'm trying to make a basket in my web site using cookies, I want my cookie file to be expired whenever ALL the pages of my site are closed. I think for doing this, I have to put a counter in my cookie file, that whenever a link is opened in a new window, I increment that counter, and of course whenever a window of my site is closed, I decrement my counter [ the number of counter is written each time in the cookie file ], so, what I get is that in the last page, when the user wants to close the window, I read the cookie file again, and when I see the counter is 1, it means that it's the last page, so, I can delete the whole entries and it means that the next time that the same user tries to enter my site, his/her cookie list will be empty, so, how can I find out when a link is opened in a new window, I mean the user right clicked on the link and chose "open in a new window"?
joh6nn
09-06-2002, 01:56 AM
to the best of my knowledge, cookies do that automatically, so you don't have to worry about.
just to see if i could, i tried to come up with a way to do what you asked about, and i wasn't able to come up with anything.
brothercake
09-06-2002, 11:35 AM
Cookies only delete themselves automatically if they are set to be sessional.
I don't believe you can detect a page being opened in a new window in the way you mentioned - there is a generic object window.opener but I think that only applies to windows being opened through script.
I think your solution is either to use a sessional cookie, or add into your cookie logic something which detects the existence of an earlier cookie, and deletes it
joh6nn
09-07-2002, 04:03 AM
" or add into your cookie logic something which detects the existence of an earlier cookie, and deletes it"
that's like reinventing the wheel, i think. just go with the default action of the cookie. if you don't set an expiration date, then it's a session cookie. problem solved, nicht wahr?
ConfusedOfLife
09-08-2002, 12:01 AM
Well, actually what I was ordered to do ( the darn boss! ) is that whenever a the whole site, i.e the whole pages, are closed, then we don't have any item in the basket, so, what you're suggesting, is going to delete all the items if just one page is closed, right? But I also thought of another logic! I'm gonna use frames, or iframes ( maybe both! ), that I have a main menu system on top of the page, and my pages change in the bottom of the page, I mean the second row, and I'm going to use cookies in my framed page, actually the index page that contains those 2 children pages, but we still have the first problem that if someone chooses a link from the menu and wants to open it in a new page, then it's not gonna have the top.document.cookie thing that I can use! for preventing others from doing this, I had 2 ways : 1-Disabling the right click ( that I hate ), 2- Not declaring my links as <a href=""> , instead using something like <span onclick="">, that even if you right click on it, you won't have the option of opening anything in a new window! This is the best that I got till now, what's your idea?!
brothercake
09-08-2002, 12:08 AM
Even if the page is opened in a new window, it still belongs to your domain, right? So document.cookie will still expose its data.
When someone visits again, you can detect if they have a cookie you set, and you can detect how old it is which, by extrapolation, tells you whether it belongs to this session.
If it doesn't - you just delete it and put up an empty basket. Problem solved.
ConfusedOfLife
09-08-2002, 01:01 AM
When someone visits again, you can detect if they have a cookie you set, and you can detect how old it is which, by extrapolation, tells you whether it belongs to this session.
How can I detect that? Saying one hour is enough to make it an old cookie? or 2 hours? or one day? I want it to expire when all the pages are closed, not after some certain amount of time.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.