0

I have Stock Charting website where users logs in and session is stored in php.

When Users is logged , I want to restrict them to have only 3 tabs (or N tabs) at a time.When 4th tab is opened , 1st tab should have some kinda warning or I do some javascript stuffs to disable ajax going on.

I am able to store each url using following code

var location = location.href;
var old = window.sessionStorage.getItem("activetabs");
old = JSON.parse(old);
newone = old.push(location);
newonestring = JSON.stringify(newone);
window.sessionStorage.setItem("activetabs", location);

I tried to setTimeout and check every 10 seconds if the url is not in last 3 elements.But duplicate url will not work here.

PS : I am trying to block the old url's if its all same URL or different URL's ,but all url are same domain.

Gracie williams
  • 1,287
  • 2
  • 16
  • 39
  • If this is meant to be a security measure, know that anything you do in JavaScript can be ignored/overridden by the user. What's the root problem trying to be solved here? Why specifically does it matter if users open more tabs? – David Apr 09 '21 at 20:27
  • Each tabs sends lots of server requests , I want to reduce load since users are opening multiple tabs in background.I dont want to be too strict , Even if I can restrict 80 users of 100 , my bandwidth will be reduced. – Gracie williams Apr 09 '21 at 20:28
  • Let's look at the problem and not the assumed solution then. Why does the page send so many requests? (Enough to cause a problem for the server.) Can that be reduced? – David Apr 09 '21 at 20:29
  • Its advanced charting library and I have lots of prices , volume data coming in., I even have websocket connections.. since users expects very low latency , I want to keep my servers traffic light as possible. – Gracie williams Apr 09 '21 at 20:31
  • what happens when i close a tab? – Nikki9696 Apr 09 '21 at 20:35
  • Hmm... I still really think improving the performance of the app itself is the way to go. It sounds like the back-and-forth between the server and the client is inefficient. But looking around, it's possible what you're asking is essentially a duplicate of [this](https://stackoverflow.com/questions/30726627/restriction-on-number-of-opened-tabs)? – David Apr 09 '21 at 20:36
  • 1
    There is no point updating the inactive tabs if the user can't see them so you may as well not update them at all until they come back to the page. So the number of tabs is irrelevant when using this method. To detect if current tab is active or not see: https://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active – John Apr 09 '21 at 21:47

0 Answers0