seems like that you want achieve, that is very difficult in client side, because at the end of scenario we have to depend for server for count, and If you can achieve this by JS(by calling AJAX), still It will not correct all the time(like It will not work in browser crash or anything It may be).
So I am telling another solution which is best suitable for this one I think, you can create webSocket connection for every logged in user, and then check If that user has max connection then you can simply display prompt,
advantage of this solution is:
You can also check cross browser(Like If someone is logged in one browser and open 3 tabs, and same user also use another browser and also using 3 tabs there, you can simply take over this too).
Thanks, Let me know if you have any query/question. I will try to give best solution :)