I am working on an application that will support working in multiple tabs at the same time. Currently, when a document is locked by a user, other users won't be able to acces the same document but the same user could, if he wanted, open that same document again in a new tab.
My problem at the moment is, when the user close one of the tab, the lock is undone for that document even if there is multiple tab opened of the same document.
I was thinking about adding a counter to my lock but if the person refresh the page, that would only increment the lock. There is also the possibility to unlock the document when the page is unloaded, but it would be possible for another request to lock the document before it has been reloaded by the user.
Is there a better way to go for locking documents for a user in a web application like that?