0

I have a site I'm building where a user clicks a row from a datagrid and it opens a new Chrome window with a form filled with data from the row. I only want one user editing the data at a time so if another user gets in, the screen is read-only. I do this by setting a LockUserID and LockDate on the row after a user enters. The minute the first user (lockuser) saves the data it will close the window and null out the LockUserID and LockDate so then next person can get in.

My problem is if a user clicks the chrome x button I don't know that the user left therefore the LockUserID and LockDate still have a value on the row and anyone that gets in afterward will have a read only view.

I have tried using before unload but this almost feels like a hack considering beforeunload is used for refreshing and other events.

Does anyone have any better suggestions with locking?

Dicpherrr
  • 117
  • 5

1 Answers1

0

Maybe you can send a regular AJAX request to the server. Let's say every 30 seconds. The server saves the time. When a new user tries to open the side you can check if the interval is bigger between the last incoming request and the current time than the 40 seconds and if so unlock the site.

Not the best solution i think but it should work

Or the better solution: Run JavaScript code on window close or page refresh?

ShadowLp174
  • 502
  • 2
  • 9