1

I have made a laravel 5.2 app which records transaction of a warehouse .. now my client wants me to give a feature which will prevent his employees from closing the browser.I know it is possible in desktop apps.My client wants to prevent his employees from stealing the money by not saving the transaction. Is there any way i can prevent the user from not being able to close the browser/window or can i record everything if someone closes the browser/tab/window without clicking save button (to catch the criminal :D)

Ahnaf
  • 149
  • 5
  • 18
  • http://stackoverflow.com/questions/2229942/how-to-block-users-from-closing-a-window-in-javascript – Alexan Jul 01 '16 at 17:02

2 Answers2

1

No, you cannot prevent the user from closing the browser from via your web site, neiter from server, nor from client side. Special software installed on the computer may make it possible, but the employer could e.g. simply kill the browser process.

One workaround that would make data loss less likely (though not impossible) would be to automatically save the data every time the user changes anything on the front end, e.g. via XMLHttpRequests.

In any case, you have to ensure in the backend (which is not in the control of the end user), that only complete and valid transactions are being saved and incomplete transactions are discarded. By doing this, the issue you are describing should be completely avoidable.

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94
  • is it possible to notify the backend that user has closed the window? – Ahnaf Jul 01 '16 at 17:10
  • Not necessarily. You have `onbeforeunload`, which can be used to execute some code when the user closes the page regularly. However, if the browser closes in an irregular fashion (e.g. the task is killed), the code won't be executed. – TimoStaudinger Jul 01 '16 at 17:13
0

It is also very simple to check if a transaction was completed or not and who worked on it. The moment, the employee logs in or starts a new transaction, a flag is set, which indicates an unfinished transaction. This event is also documented in a log. When the transaction is finished correctly, the flag is removed and another logentry is created. If not, there are irregularities visible in the log. In this way, it is also possible to set a time limit for the duration of an transaction.

Eierschale
  • 43
  • 5