In javascript, you can set cookies by path only if you are on that path already like so:
If you are at www.yourwebsite.com/firstTab
you can set this cookie:
document.cookie = "myField=blah;expires=10/10/2020;path=/firstTab";
And if you are at www.yourwebsite.com/secondTab
you can set this cookie:
document.cookie = "myField=blah2;expires=10/10/2020;path=/secondTab";
If you go to /firstTab
and do document.cookie
, you will only see myField=blah
and if you do the same in /secondTab
you will only see myField=blah2
. Here's the W3Schools tutorial for javascript cookies.
If you want to include information that's passed from C#, simply add it into a hidden field and get it from there using javascript.
Caveat
If your tabs take you to different paths then this works. But if you only use hashes then it won't work because the hash is not part of the path. You can see this with document.location
. You'll have to share cookies across tabs and parse the values yourself.