We help IT Professionals succeed at work.

How to build a web site

326 Views
Last Modified: 2017-04-08
What is the best practice to organize a web site such way it would keep its own session on each browser's tab? Is it even possible?
The problem, that the cookies are shared between the tabs and when the user refreshes a tab's content, the server is unable to determine which tab the request came from.
Having data and/or the session ID in the URL is not an option. Is there something in the latest web standards and API's which could be utilized ?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Embed a value in the page and use JavaScript to send that value back.
zc2
CERTIFIED EXPERT

Author

Commented:
Send using what? A separate HTTP request? Make a TCP/IP connection? Something else?
 How to make that JS be executed when the user switches to another tab and refresh it by pressing F5? The server should know which tab is being refreshed, but JS did not have a chance to execute, since it's just a refresh.
Please explain in details.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
Apologies I posted in haste as I had to go somewhere.

You can add an id to the URL.
Example
http://www.yourdomain.com?tab=123#tabid
This should still work with tabs but it gives a unique ID for what page your on

Cookies can be set by URL (folder) - so if your different browser tabs run off different folders then you can set the cookie by that.

What sort of URL structure are you using - absolute (points to actual resource) or rewritten - interpret with .htaccess or similar and redirect to another script?
zc2
CERTIFIED EXPERT

Author

Commented:
Say, a tab shows a page by a url with tab=123 . Then the user focuses the address bar and presses Ctrl+Enter (Alt+Enter in some browsers) and a new tab opens. How the server would know its a new tab and the url param should be changed to tab=456 ?

No we don't use URL rewrite in the site inner logic, except for the landing pages, canonical and https redirects etc.
zc2
CERTIFIED EXPERT

Author

Commented:
Basically, my question is: are there new technologies based and HTML5 and new web APIs which could help achieve that goal and I might not be aware of because they are new? If the answer is "No", that is acceptable.
Dave BaldwinFixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
The answer is no by default - I have a potential work around though - will try and post a bit later.
zc2
CERTIFIED EXPERT

Author

Commented:
Julian Hansen, any additional input is surely appreciated.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
zc2
CERTIFIED EXPERT

Author

Commented:
Thank you for detailed explanation. Actually, we have implemented a similar solution, but we keep the tab id in the sessionStorage object instead. The solution is complex and bulky, so I'm dreaming to get rid of it and replace with something simplier.
The use case is - the client we do the web site for, explicitly stated that they want to be able to be logged in as different users in tabs, and it's not an option to use different browsers.
Question: you said after generation the tab's key the script adds a parameter to the URL. How to do that without refreshing the whole page? I see, some sites are able to, like google maps changes the url when the map is panned.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
var tabid = getTabIdUsingWhatEverProcessYouHaveForThis();
var url = window.location.href + "&tabid=" + tabid;
window.location = url;

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You would need to check for parameters first though and then decide whether to use ? or & for your new parameter
var url = window.location.href;
var c = (url.indexOf('?') == -1) ? '?' : '&';
url += c + "tabid=" + tabid;
window.location = url;

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
zc2
CERTIFIED EXPERT

Author

Commented:
I opened up the F12 inspector in Chrome and executed the following command in the console
window.location=location.href+"?aaa=bbbbb"
I clearly see the browser sends a request to the server for the new page and the whole page refreshes.

But when I open maps.google.com and pan the map I see the URL is changed, but the inspector shows no "Doc" type request were made, only XHR requests for new map data. How that could be achieved?

Should I open a new following up question on EE?
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
zc2
CERTIFIED EXPERT

Author

Commented:
Thank you very much!
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You are welcome.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.