This is a response not to the original asker, but to anyone who finds this question via search. This post is designed to give you the information and arguments you need to return to your boss or your client and tell them why this design is not able to be realized. The beforeunload solution is provided by the top answer to this question. Good luck getting them on-board!
The design in this project stipulates that some javascript code should prevent the user from closing a web page, without providing the user with a dialog box. There is one key problem with this: this is something which malicious websites also try to do. Web browser developers work to prevent malicious websites from taking over the user experience. For that reason, there is no good way to do this. Even if we find a solution, that solution will not be future-proof, and will break without warning coinciding with a browser update.
Web browser developers provide exactly one solution to us for preventing the close of the websites. That solution is called "the beforeunload solution". The beforeunload solution will give the user a dialog box, and the text in that dialog box will have standardized, boilerplate text with a "stay" button and a "leave" button. We can add some text to that dialog box, but we cannot remove the boilerplate text and we cannot change, move or otherwise manipulate the buttons. The beforeunload solution is inflexible, but it is future-proof.
Using a non-standard solution (otherwise known as a hack) to circumvent what beforeunload provides will thrust us into the arms-race between malicious websites and the web browser developers, and we will not be able to guarantee that our website's features will work consistently from day-to-day. Malicious websites often find new tricks and hacks to keep intrusive advertisements on-screen, so even if we find something which is allowed one day it might be banned the next. The internet is littered with no-longer-working non-standard solutions which web browser developers have shut down!
The beforeunload solution is the only workable solution in the long-term, and we will need to accept that the end-user can close our website for any reason, using any standard keyboard shortcut, and the only way we can prevent this is a dialog box which requests that they stay on the site.