I tried looking everywhere. For the past few days, with dreaded eyes, I searched every other place in web, but no where I get anything which remotely close to what I am looking for.
All I know is that beforeunload doesn't work in Mobil Safari.
Why I need it? I am developing a solution where if user try to open the same app. in another tab, system will alert the user and not let him login. This solution uses localStorage and works good so far in every where except iPad Safari browser. Is there anyone here faced the same issue and got any solution? Help out a tired, weary fellow guys!
Ideally it should work because localStorage is supported in Safari. Either check in the settings if you have disabled JavaScript or run it on different iPad to verify if the problem is with the code.
Also, Wouldn't it be better if this is handled in the server side based on active session? storing in localStorage is vulnerable and wouldn't work in incognito mode
Rajkumar
Fullstack Developer.
Jason Knight
The less code you use, the less there is to break
Why don't you want people being able to have multiple copies open? Usually that's an advantage -- at least for the user -- since then you can put them side-by-side and look at different parts at the same time?
Generally a tab/window being closed is none of a web app's business, I'm surprised you got it to work at all -- but...
How about you set up a push or polling system where every time a new copy is opened, you give it a unique random hash. When a copy is opened you push "X hash opened for Y user" and have each open copy of the app respond "I'm here". If more than one responds, warn in the new ones but not the oldest one. It's a bit more back-and-forth but would be more reliable than trying to trap the tab closure.
Especially since it could go cross-browser / cross-machine. That way if you have a reason to never allow more than one copy open they can't open it on the desktop and their mobile device at the same time.