By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,070 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,070 IT Pros & Developers. It's quick & easy.

creating browser tab specific cookie

P: 29
I am working on transactional website.
I am storing transaction identifier (a unique id) in a cookie, so that I can display transaction history to user.

Now a days modern browsers support multiple tabs in same window.

I am facing a problem when user starts two different transaction in two different tabs in same browser window. I am unable to differentiate between different browser tabs, because which same cookie is getting overwritten, in both the tabs.

Is there any way by which I can create tab specific cookie? which won't be accessible in another tab? Or is there any unique identifier for tabs?

I am creating cookie using java script.
Dec 6 '09 #1

✓ answered by sorokin88

I think you can store you data in the "window.name" variable. It is tab or window specific and stays the same as user moves from one page to another (until you change it using javascript).

If a user opens your site in a new tab or clicks a link to open target page in a new tab, the value won't be copied and will be empty there.

Share this Question
Share on Google+
12 Replies


acoder
Expert Mod 15k+
P: 16,027
Why not reuse the same transaction id in the second tab[*], so they cannot login with two different IDs at the same time (unless they use a different browser)?

[*]check for the ID. If exists, reuse, if not create new one.
Dec 6 '09 #2

P: 15
Could you encode some session identifier into the URL, so that different tab environments have different URLs.

Depending on the lifecycle of the page you could use a timestamp and then alsocheck if the page had been "backed".
Dec 6 '09 #3

P: 29
@acoder
Actually, the problem is user comes to the page select product and then goes to the payment page. Now payment page is showing him 500 Rs. User opens new tab purchase a product costing 1000 Rs.

Now I am storing transaction id in a single cookie. So first cookie got overridden. In this case only one tab is valid, so he can pay for Rs. 1000 and after a payment confirmation cookie is deleted, so the transaction for the previous amount (Rs. 500) is gone away.

In many cases users go to payment page in first tab to pay 500 Rs. (Page is not refreshed so it still shows Rs. 500) but a cookie says its 1000 Rs. Transaction and sends that much to bank.

That means user submitted Rs. 500 and paid Rs. 1000 instead.
Dec 26 '09 #4

P: 29
@DMsy2
I already thought of this, but the problem is I have to pass transaction id through URL. Furthermore, I am maintaining user friendly URL's, so not a good idea.

In addition, I am allowing users to navigate the entire website and come back for payment, so I have to keep track of this on all the pages (Even on static HTML pages).

Even It's very difficult to pass it using form post on all over the website.
Dec 26 '09 #5

P: 3
I think you can store you data in the "window.name" variable. It is tab or window specific and stays the same as user moves from one page to another (until you change it using javascript).

If a user opens your site in a new tab or clicks a link to open target page in a new tab, the value won't be copied and will be empty there.
Dec 27 '09 #6

Dormilich
Expert Mod 5K+
P: 8,639
I think you can store you data in the "window.name" variable.
in fact, every globally defined variable can do that.
Dec 27 '09 #7

P: 3
Dormilich, I don't think every globally defined variable can survive after you click a link on the site to load another page...
Dec 27 '09 #8

Dormilich
Expert Mod 5K+
P: 8,639
well, I doubt that window.name, resp. its content will.
Dec 27 '09 #9

P: 3
It is easier to check it out than to doubt.
Dec 28 '09 #10

acoder
Expert Mod 15k+
P: 16,027
Actually, the problem is user comes to the page select product and then goes to the payment page. Now payment page is showing him 500 Rs. User opens new tab purchase a product costing 1000 Rs.

Now I am storing transaction id in a single cookie. So first cookie got overridden. In this case only one tab is valid, so he can pay for Rs. 1000 and after a payment confirmation cookie is deleted, so the transaction for the previous amount (Rs. 500) is gone away.
As I said, why not keep one cookie for a single user, so they can have two transactions stored in one cookie? If that's a problem, store the transactions with one ID, so for example, they go to payment (amount 500), then they open another tab. It will show 500 in their basket/shopping cart. If they now purchase another item for 1000, it will have two items and a total of 1500.
Dec 30 '09 #11

P: 29
@sorokin88
I have a doubt, whether it is accessible in a child window (popup) or not, but seems to be a better idea will try this and will let you know on success.
Jan 1 '10 #12

P: 29
I tried this in Firefox and its working fine. It won't work in case if the new window is opened with the attribute target="_blank" (considered as new window I guess).
Jan 1 '10 #13

Post your reply

Sign in to post your reply or Sign up for a free account.